Moving value to a textbox control from another thread

Jan 20 2009 8:13 AM

i'm in big trouble moving some value to a textbox control from another thread. i need anybody's help to solve it..

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Threading;

namespace webbrowser

{

public partial class WebBrowser : Form

{

public delegate void DisplayHandler(string stringMessage);

public DisplayHandler DisplayMessage;

public WebBrowser()

{

InitializeComponent();

}

private void WebBrowser_Load(object sender, EventArgs e)

{

Thread threadSocket = new Thread(new ThreadStart(StartSocket));

threadSocket.Start();

}

public static void StartSocket()

{

SocketServer mySocket = new SocketServer();

mySocket.SocketDataArrival += new SocketServer.SocketServerHandler(ShowDataArrival);

mySocket.InititateServer();

}

public void TextBoxHandler()

{

DisplayMessage = new DisplayHandler(this.UpdateTextMethod);

}

public void UpdateTextMethod(string s)

{

TxtBoxMsg.Text = s;

}

 

static void ShowDataArrival(object a, SocketServerArgs e)

{

//e.Message returns string from mysocketServer

DisplayHandler d = new DisplayHandler(e.Message);

d.Invoke(e.Message);

}

}

}


Answers (2)