aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/RmlsView.xaml.cs
blob: 66f52d8c862372968b624be3c919ae5b94b33d35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Tango.MachineStudio.RML.Views
{
    /// <summary>
    /// Interaction logic for RmlsView.xaml
    /// </summary>
    public partial class RmlsView : UserControl
    {
        public RmlsView()
        {
            InitializeComponent();
        }
    }
}
w"> { public event EventHandler ServerNotResponding; private NamedPipeClientStream _client; private StreamReader _reader; private StreamWriter _writer; private Thread _thread; public bool IsStarted { get; private set; } public TimeSpan Interval { get; set; } public WatchDogClient() { Interval = TimeSpan.FromSeconds(5); } public void Start() { if (!IsStarted) { LogManager.Log("Starting watchdog client..."); IsStarted = true; _thread = new Thread(ThreadMethod); _thread.IsBackground = true; _thread.Start(); } } private void ThreadMethod() { try { LogManager.Log("Watchdog client started."); while (IsStarted) { _client = new NamedPipeClientStream("Tango_Watch_Dog_Pipe"); _client.Connect(5000); _reader = new StreamReader(_client); _writer = new StreamWriter(_client); _writer.WriteLine("ping"); _writer.Flush(); var line = _reader.ReadLine(); if (line != "ping") { LogManager.Log("Watchdog server not found. Raising notification..."); try { IsStarted = false; _client.Dispose(); } catch { } ServerNotResponding?.Invoke(this, new EventArgs()); return; } _client.Dispose(); Thread.Sleep(Interval); } } catch (Exception ex) { IsStarted = false; LogManager.Log(ex, "Error in watchdog client."); ServerNotResponding?.Invoke(this, new EventArgs()); } } public void Stop() { IsStarted = false; _client.Dispose(); } } }