跨线程调用form控件技巧
private delegate void MethodSocket(object obj);//使用托管
ss = "OK";
this.BeginInvoke(new MethodSocket(InvokerReadMsg), ss);//this指向本窗口,回调函数InvokerReadMsg, private void InvokerReadMsg(object obj)//在这个函数里面能够直接訪问Form控件<span style="font-family: Arial, Helvetica, sans-serif;">txtContent</span> {
this.txtContent.Text += obj.ToString() + "\r\n";
}
byte[]与string型相互转换
//byte 转string
string test = Encoding.Default.GetString(bytes, 0, length);
//string 转 byte
byte[] bytes = System.Text.Encoding.Default.GetBytes(test);