public void receiveMsg(Form main, pointer_to_funcation f) { Thread t2 = new Thread(receiveMsg2); t2.Start(new object[2] { main, f }); //call the thread+params }
public void receiveMsg2(object obj) { object[] objs = (object[])obj; Form main = (Form)objs[0]; pointer_to_funcation f = (pointer_to_funcation)objs[1]; string msg = ""; try { NetworkStream ns = client.GetStream(); //byte[] binary = ns.Read(); byte[] binary = new byte[100]; ns.Read(binary, 0, binary.Length); msg = UnicodeEncoding.Unicode.GetString(binary); main.Invoke(f, msg); //return msg; } catch { return; } }