Renamed Step.Tasks in Step.Core
This commit is contained in:
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using TeamDev.SDK.MVVM;
|
||||
using static Step.Model.Constants;
|
||||
|
||||
namespace Step.Core
|
||||
{
|
||||
public static class ThreadsHandler
|
||||
{
|
||||
private static List<Action> ThreadsFunctionsList = new List<Action>
|
||||
{
|
||||
ThreadsFunctions.ReadAlarms,
|
||||
ThreadsFunctions.ReadPowerOnData,
|
||||
ThreadsFunctions.StatThread,
|
||||
ThreadsFunctions.ReadProcessesPPStatus,
|
||||
ThreadsFunctions.ReadEnabledFunctionality,
|
||||
ThreadsFunctions.ReadExpiredMaintenances,
|
||||
// ThreadsFunctions.ReadNcSoftKeysData,
|
||||
ThreadsFunctions.ReadUserSoftKeysData,
|
||||
ThreadsFunctions.ReadHeadsData,
|
||||
ThreadsFunctions.ReadAxesNamesData
|
||||
};
|
||||
|
||||
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()
|
||||
{
|
||||
lock (RunningThreadStatus)
|
||||
RunningThreadStatus.Clear();
|
||||
|
||||
// For each function run in the list a thread
|
||||
ThreadsFunctionsList.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();
|
||||
|
||||
lock (RunningThreadStatus)
|
||||
{
|
||||
RunningThreadStatus.Clear();
|
||||
RunningThreadStatus.Add("TryNcConnection", "---");
|
||||
}
|
||||
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
|
||||
}
|
||||
|
||||
public static void Close()
|
||||
{
|
||||
//Abort Nc Read Threads
|
||||
RunningThreadsList.ForEach(thread =>
|
||||
{
|
||||
thread.Abort();
|
||||
});
|
||||
|
||||
//Abort Connect Thread
|
||||
ThreadsFunctions.AbortNcConnection();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user