//private bool SocketConnected(Socket s) //{ // bool a = sck.Poll(1000, SelectMode.SelectRead); // bool b = (s.Available == 0); // if (a && b) // { // return false; // } // return true; //} private void Window_Closing(object sender, CancelEventArgs e) { var userPrefs = new UserPreferences { WindowHeight = Height, WindowWidth = Width, WindowTop = Top, WindowLeft = Left, WindowState = WindowState }; Settings.Default.IsRemoteConnected = false; userPrefs.Save(); }
public MainWindow() { InitializeComponent(); var role = Settings.Default.Role; lblHeader.Content = "Poli " + role; cmd = new DBCommand(DBConnection.dbConnection()); InitSerialPort(); try { //sck = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); //sck.Connect(Settings.Default.SocketServerAntri, Settings.Default.SocketPortAntri); clientAntrianPoli = new SimpleTcpClient(); clientAntrianPoli.StringEncoder = Encoding.UTF8; clientAntrianPoli.DataReceived += ClientAntrianPoli_DataReceived; clientAntrianPoli.Connect(Settings.Default.SocketServerAntri, Settings.Default.SocketPortAntri); } catch (Exception) { // ignored } try { sp.DataReceived += Sp_DataReceived; sp.ErrorReceived += Sp_ErrorReceived; sp.Open(); } catch (Exception) { InitSerialPort(); } var userPrefs = new UserPreferences(); Height = userPrefs.WindowHeight; Width = userPrefs.WindowWidth; Top = userPrefs.WindowTop; Left = userPrefs.WindowLeft; WindowState = userPrefs.WindowState; }