80 lines
2.3 KiB
C#
80 lines
2.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using CMS_CORE;
|
|
using CMS_CORE.Demo;
|
|
using CMS_CORE.Fanuc;
|
|
using CMS_CORE.Osai;
|
|
using CMS_CORE.Siemens;
|
|
using Step.NC;
|
|
using static Step.Config.ServerConfig;
|
|
using static Step.Utils.Constants;
|
|
using TeamDev.SDK.MVVM;
|
|
using System.Diagnostics;
|
|
|
|
namespace Step.Core
|
|
{
|
|
public static class ThreadsHandler
|
|
{
|
|
private static List<Action> ThreadFunctionsList = new List<Action>
|
|
{
|
|
ThreadsFunctions.ReadAlarms,
|
|
ThreadsFunctions.ReadNcGenericInfo,
|
|
ThreadsFunctions.ReadAxes,
|
|
ThreadsFunctions.ReadPowerOnData,
|
|
ThreadsFunctions.StatThread
|
|
};
|
|
private static List<Thread> RunningThreadsList = new List<Thread>();
|
|
internal static Dictionary<String, String> RunningThreadStatus = new Dictionary<String, String>();
|
|
private static Thread StatThread;
|
|
|
|
public static void Start()
|
|
{
|
|
ThreadsFunctions.TryNcConnection();
|
|
}
|
|
|
|
public static void StartWorkers()
|
|
{
|
|
|
|
RunningThreadStatus.Clear();
|
|
|
|
// For each function run in the list a thread
|
|
ThreadFunctionsList.ForEach(threadFunction =>
|
|
{
|
|
// Run new Thread in the list
|
|
Thread t = new Thread(() =>
|
|
threadFunction()
|
|
);
|
|
t.Start();
|
|
// Add thread to running threads list
|
|
RunningThreadsList.Add(t);
|
|
|
|
RunningThreadStatus.Add(threadFunction.Method.Name, "---");
|
|
});
|
|
|
|
MessageServices.Current.Publish(MVVM_NC_THREADS, null, RunningThreadStatus);
|
|
}
|
|
|
|
public static void Stop()
|
|
{
|
|
|
|
// Stop each thread
|
|
RunningThreadsList.ForEach(thread =>
|
|
{
|
|
thread.Abort();
|
|
});
|
|
|
|
// Remove threads from running status
|
|
RunningThreadsList.Clear();
|
|
|
|
RunningThreadStatus.Clear();
|
|
RunningThreadStatus.Add("TryNcConnection", "---");
|
|
MessageServices.Current.Publish(MVVM_NC_THREADS, null, RunningThreadStatus);
|
|
}
|
|
}
|
|
}
|
|
|