1.第一个问题,关于,回调函数是否必须为静态函数或者全局函数?
2.第二个问题,静态函数,如何操作Form中的控件?
public static Form1 form1;
public Form1()
{
InitializeComponent();
form1 = this;
}
state.workSocket = handler;
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
public static void ReadCallback(IAsyncResult ar)
{
Form1.form1.textBoxReceive.AppendText(strmsgtemp);
}
3.第三个问题:非创建控件线程,无法访问
//非创建控件线程,无法访问
//richTextBox1.AppendText(Encoding.ASCII.GetString(data, 0, recvlength));
delegate void richtexttip();
richtexttip richtext3 = delegate()
{
richTextBox1.AppendText("client:"+Encoding.Unicode.GetString(data, 0, recvlength) + "\r\n");
};
richTextBox1.Invoke(richtext3);