d350183fb5
+ Added new library version (30) with pre and post power on data * Refactor
83 lines
2.1 KiB
C#
83 lines
2.1 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 volatile static List<Thread> RunningThreadsList = new List<Thread>();
|
|
internal volatile static Dictionary<String, String> RunningThreadStatus = new Dictionary<String, String>();
|
|
|
|
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
|
|
lock (RunningThreadsList)
|
|
RunningThreadsList.Add(t);
|
|
|
|
|
|
RunningThreadStatus.Add(threadFunction.Method.Name, "---");
|
|
});
|
|
|
|
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
|
|
}
|
|
|
|
public static void Stop()
|
|
{
|
|
|
|
// Stop each thread
|
|
lock (RunningThreadsList)
|
|
RunningThreadsList.ForEach(thread =>
|
|
{
|
|
thread.Abort();
|
|
});
|
|
|
|
// Remove threads from running status
|
|
lock (RunningThreadsList)
|
|
RunningThreadsList.Clear();
|
|
|
|
RunningThreadStatus.Clear();
|
|
RunningThreadStatus.Add("TryNcConnection", "---");
|
|
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
|
|
}
|
|
}
|
|
}
|
|
|