/// <summary> /// 异步向服务器端发送数据 /// </summary> /// <param name="message"></param> private void AsyncSendMessage(string message) { SendMessageDelegate d = new SendMessageDelegate(SendMessage); IAsyncResult result = d.BeginInvoke(message, null, null); while (result.IsCompleted == false) { if (isExit) { return; } Thread.Sleep(50); } SendMessageStates states = new SendMessageStates(); states.d = d; states.result = result; Thread t = new Thread(FinishAsyncSendMessage); t.IsBackground = true; t.Start(states); }
/// <summary> /// 异步向服务器发送数据 /// </summary> /// <param name="message"></param> public void AsyncSendMessage(string message) { SendMessageDelegate d = new SendMessageDelegate(SendMessage); IAsyncResult result = d.BeginInvoke(message, null, null); while (!result.IsCompleted) { if (isExit) { return; } Thread.Sleep(50); } SendMessageStates states = new SendMessageStates(); states.d = d; states.result = result; FinishAsyncSendMessage(states, null); //Thread t = new Thread(new ThreadStart(FinishAsyncSendMessage)); //t.IsBackground = true; //t.Start(); }
/// <summary> /// 处理接收的服务器端数据 /// </summary> /// <param name="obj"></param> private void FinishAsyncSendMessage(object obj) { SendMessageStates states = (SendMessageStates)obj; states.d.EndInvoke(states.result); }
/// <summary> /// 异步向服务器发送数据 /// </summary> /// <param name="message"></param> private void AsyncSendMessage(CilentInfo message) { SendMessageDelegate d = new SendMessageDelegate(SendMessage); IAsyncResult result = d.BeginInvoke(message, null, null); while (!result.IsCompleted) { if (isExit) return; Thread.Sleep(50); } SendMessageStates states = new SendMessageStates(); states.d = d; states.result = result; Thread t = new Thread(FinishAsyncSendMessage); t.IsBackground = true; t.Start(states); }
///// <summary> ///// 处理接收的服务端数据 ///// </summary> ///// <param name="obj"></param> //private void FinishAsyncSendMessage(object obj) //{ // SendMessageStates states = (SendMessageStates)obj; // states.d.EndInvoke(states.result); //} /// <summary> /// 处理接收的服务端数据 /// </summary> /// <param name="obj"></param> private void finishAsyncSendMessage(object obj, EventArgs e) { SendMessageStates states = (SendMessageStates)obj; states.d.EndInvoke(states.result); }