// cross thread safe handler private void ProcessMessage(DataReceivedEventArgs arg, string text) { // InvokeRequired required compares the thread ID of the // calling thread to the thread ID of the creating thread. // If these threads are different, it returns true. if (this.InvokeRequired) { ProcessMessageCallback d = new ProcessMessageCallback(ProcessMessage); this.Invoke(d, new object[] { arg, text }); } else { if (text.StartsWith("ADMIN")) { HandleMessage(arg, text); } else if (text.StartsWith("LOGIN")) { string _response = text; if (_response == Msg.LOGIN_OK) { lblStatus.Text = "Connected to Server : " + client.Session.RemoteInfo + " - Post :" + Tobasa.Properties.Settings.Default.StationPost + " Station:" + Tobasa.Properties.Settings.Default.StationName; Logger.Log("QueueAdmin : Successfully logged in"); } else { string reason = _response.Substring(10); string msg = "QueueAdmin : Could not logged in to server, \r\nReason: " + reason; Logger.Log(msg); MessageBox.Show(this, msg, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); CloseConnection(); } } else { tbLog.AppendText("\r\n" + text); string logmsg = String.Format("Unhandled session message from: {0} - MSG: {1} ", arg.RemoteInfo, text); Logger.Log(logmsg); } } }
/// cross thread safe handler private void ProcessMessage(DataReceivedEventArgs arg, string text) { /// InvokeRequired required compares the thread ID of the /// calling thread to the thread ID of the creating thread. /// If these threads are different, it returns true. if (this.InvokeRequired) { ProcessMessageCallback d = new ProcessMessageCallback(ProcessMessage); this.Invoke(d, new object[] { arg, text }); } else { if (text.StartsWith("TICKET")) { HandleMessage(arg, text); } else if (text.StartsWith("LOGIN")) { string _response = text; if (_response == Msg.LOGIN_OK) { Logger.Log("QueueTicket : Successfully logged in"); } else { string reason = _response.Substring(10); string msg = "QueueTicket : Could not logged in to server, \r\nReason: " + reason; Logger.Log(msg); MessageBox.Show(this, msg, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); CloseConnection(); } } else { string logmsg = String.Format("Unhandled session message from: {0} - MSG: {1} ", arg.RemoteInfo, text); Logger.Log(logmsg); } } }
/// cross thread safe handler public void ProcessMessage(DataReceivedEventArgs arg, string text) { /// InvokeRequired required compares the thread ID of the /// calling thread to the thread ID of the creating thread. /// If these threads are different, it returns true. if (this.InvokeRequired) { ProcessMessageCallback d = new ProcessMessageCallback(ProcessMessage); this.Invoke(d, new object[] { arg, text }); } else { if (text.StartsWith("DISPLAY")) { HandleMessage(arg, text); } else if (text.StartsWith("LOGIN")) { string _response = text; if (_response == Msg.LOGIN_OK) { lblStatus.Text = "Connected to Server : " + client.Session.RemoteInfo + " - Post :" + Properties.Settings.Default.StationPost + " Station:" + Properties.Settings.Default.StationName; Logger.Log("QueueDisplay : Successfully logged in"); // Request running text from server client.Send("DISPLAY" + Msg.Separator + "GET_RUNNINGTEXT"); } else { string reason = _response.Substring(10); string msg = "QueueDisplay : Could not logged in to server, \r\nReason: " + reason; Logger.Log(msg); MessageBox.Show(this, msg, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error); CloseConnection(); } } } }
static extern void TestCallback(ProcessMessageCallback callback);