/// <summary> /// Connect and Send Information to Server /// </summary> public static void NotifactionFromServer() { try { clientNotifaction = new ClientNotificationClient("NetTcpBinding_IClientNotification"); string counterNumber = Properties.Settings.Default.CounterNumber.ToString(); new Task( new Action(() => { while (true) { try { ObservableCollection <CommandData> commands = new ObservableCollection <CommandData>(clientNotifaction.GetCommands(counterNumber)); if (commands.Count > 0) { foreach (CommandData comm in commands) { clientNotifaction.RemoveCommand(counterNumber); switch (comm.Command) { case Commands.Shutdown: Process.Start("shutdown", "/s /t 0"); break; case Commands.Restart: Process.Start("shutdown", "/r /t 0"); break; case Commands.AccountLogout: Counter.counterWindow.Dispatcher.BeginInvoke(new Action(Counter.counterWindow.Close), DispatcherPriority.Normal); break; default: break; } } } System.Threading.Thread.Sleep(6000); } catch { break; } } })).Start(); } catch { System.Threading.Thread.Sleep(10000); NotifactionFromServer(); } }
/// <summary> /// Connect and Send Information to Server /// </summary> public static void NotifactionFromServer() { try { clientNotifaction = new ClientNotificationClient("NetTcpBinding_IClientNotification"); string counterNumber=Properties.Settings.Default.CounterNumber.ToString(); new Task( new Action(() => { while (true) { try { ObservableCollection<CommandData> commands = new ObservableCollection<CommandData>(clientNotifaction.GetCommands(counterNumber)); if (commands.Count > 0) { foreach (CommandData comm in commands) { clientNotifaction.RemoveCommand(counterNumber); switch (comm.Command) { case Commands.Shutdown: Process.Start("shutdown", "/s /t 0"); break; case Commands.Restart: Process.Start("shutdown", "/r /t 0"); break; case Commands.AccountLogout: Counter.counterWindow.Dispatcher.BeginInvoke(new Action(Counter.counterWindow.Close), DispatcherPriority.Normal); break; default: break; } } } System.Threading.Thread.Sleep(6000); } catch { break; } } })).Start(); } catch { System.Threading.Thread.Sleep(10000); NotifactionFromServer(); } }
private void clientLogoff_Click(object obj) { ClientNotificationClient clientNotify = new ClientNotificationClient("NetNamedPipeBinding_IClientNotification"); clientNotify.setCommand(new CommandData { Command = Commands.AccountLogout, CounterNumber = obj.ToString() }); clientNotify.Close(); }