public void Start(BotTaskType _taskType) { if (p_tasks.ContainsKey(_taskType)) { return; } CancellableTaskProc proc; switch (_taskType) { case BotTaskType.NotificationAboutEvent: proc = p_eventNotificator.StartProcLoop; break; //case BotTaskType.NotificationAboutPartyAction: // proc = p_partyActionNotificator.StartProcLoop; // break; default: throw new ArgumentOutOfRangeException(nameof(_taskType), _taskType, null); } var task = new CancellableTask(proc, TaskCreationOptions.LongRunning, $"BotTask_{_taskType}"); p_tasks[_taskType] = task; task.Start(); }
public static void Start(bool _useConsole, string directoryPath, int _intervalBetweenPurge) { // Create color pattern foreach (var color in Enum.GetValues(typeof(ConsoleColor))) { colorPattern += $"({color}" + "{)" + "|"; } colorPattern += "(})"; // Save variable and instantiate logging intervalBetweenPurge = _intervalBetweenPurge; useConsole = _useConsole; if (IOSupport.IsDirectoryWriteable(directoryPath)) { logEntries = new ConcurrentQueue <LogEntry>(); Started = true; Write($"Application {Process.GetCurrentProcess().ProcessName} started (logging enabled)"); task = new CancellableTask((token) => { while (!((CancellationToken)token).IsCancellationRequested) { PurgeQueue(directoryPath); if (applicationExiting) { Write($"Application {Process.GetCurrentProcess().ProcessName} terminated", LogEntry.SeverityType.High); PurgeQueue(directoryPath); return; } task.SleepOrExit(intervalBetweenPurge); } }); task.Start(); } else { Write($"Application {Process.GetCurrentProcess().ProcessName} started (logging disabled)"); } }
public static void Register(ITimedDictionary timedDictionary) { if (timedDictionary == null) { throw new ArgumentNullException(nameof(timedDictionary)); } if (!TimedDictionaries.TryAdd(timedDictionary, DateTime.UtcNow)) { return; } if (Interlocked.Increment(ref TimedDictionartiesCount) != 1) { return; } var cleanUpTask = new CancellableTask(CleanUp); if (Interlocked.CompareExchange(ref _cleanUpTask, cleanUpTask, null) == null) { cleanUpTask.Start(); } }
public void Start() { scraperTask.Start(); }