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);
}
}
}
angelo cantillasPosted Jan 22, 2009, 7:51 AM
thank you for your effort but the code snippet is applicable only when the object receiver can be seen in a function that belongs to the same class.... the problem is when you move a value to the object receiver from another class inside a separate thread.
Ryan AlfordPosted Jan 20, 2009, 8:19 PM