private void btnMonitoring_Click(object sender, RoutedEventArgs e)
        {
            MonitorWindow MonitorW = MonitorWindow.Create(portChat);

            MonitorW.Owner = this;
            MonitorW.Show();
        }
 public static MonitorWindow Create(SerialPortChat portChat)
 {
     if (instance == null)
     {
         instance = new MonitorWindow();
     }
     instance.portChat = portChat;
     instance.portChat.RecivedAnswer += PortChat_RecivedAnswer;
     instance.WindowState             = WindowState.Normal;
     instance.commandTimer            = new Timer(new TimerCallback(SendCommand));
     instance.commandTimer.Change(500, 3000);
     return(instance);
 }
 private void Window_Closed(object sender, EventArgs e)
 {
     instance.portChat.RecivedAnswer -= PortChat_RecivedAnswer;
     instance.commandTimer.Dispose();
     instance = null;
 }