private void static Send(string messageToSend, bool requiresACK) { SendMessageDelegate sendDelegate = DoSend; IAsyncResult ar = sendDelegate.BeginInvoke(messageToSend, requiresACK); //rest of function }
public void Send(IM_Message message) { SendMessageDelegate send = new SendMessageDelegate(SendMessage); IAsyncResult iRes = send.BeginInvoke(message, new AsyncCallback(iAsyncCallbackMethod), null); while (!iRes.AsyncWaitHandle.WaitOne(100, true)) { ; } }
private void SendMessage() { try { if (listViewTo.Items.Count == 0) { MessageBox.Show(SettingList["MsgBoxEmptySelectUserTextBox"], SettingList["MsgBoxCaptionWarning"], MessageBoxButtons.OK); btnSelect.Select(); btnSelect.Focus(); return; } if (txtMsg.Text.Trim() == "") { MessageBox.Show(SettingList["MsgBoxEmptyMsgTextBox"], SettingList["MsgBoxCaptionWarning"], MessageBoxButtons.OK); txtMsg.Text = ""; txtMsg.Focus(); return; } Boolean confirmation = false; if (cbConfirm.Checked) { confirmation = true; } Cursor.Current = Cursors.WaitCursor; AsyncCallback SendMessageCallBack = new AsyncCallback(SendMessageReturned); SendMessageDelegate SMDel = new SendMessageDelegate(ServerObj.SendMessageToServer); IAsyncResult SendMessageAsyncResult = SMDel.BeginInvoke(userName + info, ListSendServer, txtMsg.Text, confirmation, SendMessageCallBack, SMDel); Cursor.Current = Cursors.Default; MessageBox.Show(SettingList["MsgBoxSendMsgOk"], SettingList["MsgBoxCaptionInfo"], MessageBoxButtons.OK); ListSendServer = null; ListSendServer = new List <string>(); ListSendServerListView = new List <string>(); listViewTo.Items.Clear(); txtMsg.Text = ""; cbConfirm.Checked = false; btnSelect.Enabled = true; btnClear.Enabled = false; btnSend.Enabled = false; cbConfirm.Enabled = false; btnClose.Focus(); } catch (Exception ex) { Cursor.Current = Cursors.Default; MessageBox.Show(SettingList["MsgBoxErrSendMsg"] + " " + ex.Message, SettingList["MsgBoxCaptionError"], MessageBoxButtons.OK); } }
/// <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(); }
public IAsyncResult BeginSendMessage(Stream message,AsyncCallback callback,object state) { if(this.IsDisposed){ throw new ObjectDisposedException(this.GetType().Name); } if(!this.IsConnected){ throw new InvalidOperationException("You must connect first."); } if(message == null){ throw new ArgumentNullException("message"); } SendMessageDelegate asyncMethod = new SendMessageDelegate(this.SendMessage); AsyncResultState asyncState = new AsyncResultState(this,asyncMethod,callback,state); asyncState.SetAsyncResult(asyncMethod.BeginInvoke(message,new AsyncCallback(asyncState.CompletedCallback),null)); return asyncState; }
/// <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); }
public Int32 SendMessage( Int32 ConnectionHandle, Hashtable InParameters, ref Hashtable OutParameters ) { Int32 ReturnCode = Constants.ERROR_CONNECTION_DISCONNECTED; if( RemoteInterfaceAlive ) { try { SendMessageDelegate DSendMessage = new SendMessageDelegate( RemoteInterface.SendMessage ); IAsyncResult Result = DSendMessage.BeginInvoke( ConnectionHandle, InParameters, ref OutParameters, null, null ); WaitHandle.WaitAny( new WaitHandle[2] { Result.AsyncWaitHandle, RemoteInterfaceDropped } ); if( Result.IsCompleted ) { ReturnCode = DSendMessage.EndInvoke( ref OutParameters, Result ); } } catch( Exception ) { SignalConnectionDropped(); } } return ReturnCode; }
private void SendMessage() { try { List <String> ListClientsInfo = new List <string>(); List <String> ListSend = new List <string>(); List <String> ListSendServer = new List <string>(); String ipAddressServer = ConfigurationSettings.AppSettings["ipAddressServer"].Trim(); int portServer = Convert.ToInt32(ConfigurationSettings.AppSettings["portServer"].Trim()); String to = ConfigurationSettings.AppSettings["to"].Trim(); String text = ConfigurationSettings.AppSettings["Text"].Trim(); if (ipAddressServer == "") { Console.Write("Parameter 'ipAddressServer' cannot be empty! Please check configuration file!"); return; } if (to == "") { Console.Write("Parameter 'to' cannot be empty! Please check configuration file!"); return; } if (text == "") { Console.Write("Parameter 'text' cannot be empty! Please check configuration file!"); return; } String hostName = Dns.GetHostName().ToLower(); if (hostName != "") { if (hostName.Length > 1) { hostName = hostName.ToLower(); hostName = hostName.Remove(1).ToUpper() + hostName.Substring(1); } else { hostName = hostName.ToUpper(); } } String userName = "******" + hostName + ")"; String serverURL = "tcp://" + ipAddressServer + ":" + portServer.ToString() + "/ServerObject.rem"; IServerObject ServerObj = (IServerObject)Activator.GetObject(typeof(IServerObject), serverURL); ListClientsInfo = ServerObj.GetClientsInfo(); if (to == "*") { ListSendServer = ListClientsInfo; if (ListSendServer.Count == 0) { Console.Write("Sorry. There is nobody to send this message."); return; } } else { String[] arrayTo = to.Split(';'); foreach (String arr in arrayTo) { String tmp = arr.Trim(); if (tmp == "") { continue; } ListSend.Add(tmp); } for (int i = 0; i < ListSend.Count; i++) { for (int j = 0; j < ListClientsInfo.Count; j++) { if (Regex.IsMatch(ListClientsInfo[j].ToString(), ListSend[i].ToString(), RegexOptions.IgnoreCase)) { ListSendServer.Add(ListClientsInfo[j].ToString().Split(')')[0].Trim() + ")"); } } } if (ListSendServer.Count > 0) { ListSendServer.Sort(); int index = 0; while (index < ListSendServer.Count - 1) { if (ListSendServer[index] == ListSendServer[index + 1]) { ListSendServer.RemoveAt(index); } else { index++; } } } else { Console.Write("Sorry. There is nobody to send this message."); return; } } AsyncCallback SendMessageCallBack = new AsyncCallback(SendMessageReturned); SendMessageDelegate SMDel = new SendMessageDelegate(ServerObj.SendMessageToServer); IAsyncResult SendMessageAsyncResult = SMDel.BeginInvoke(userName, ListSendServer, text, false, SendMessageCallBack, SMDel); Console.Write("The message has been sent."); } catch (Exception ex) { Console.Write("Cannot send this message. Either RSend server is offline or incorrect parameters in configuration file."); // + ex.ToString()); } }