public void OnAutoload(int brigadeCode, int cameraNum) { lock (tasksLock) { if (tasks.Any(x => x.BrigadeCode == brigadeCode && x.CameraNum == cameraNum)) { return; } var t = new AutoLoadVideoTask(); t.BrigadeCode = brigadeCode; t.CameraNum = cameraNum; var cts = new CancellationTokenSource(); t.Cts = cts; t.Task = new Task(async(token) => { logger.Info($"Task [{brigadeCode}({cameraNum})] autoupdate video was started"); using (var loader = AutoFileLoader.CreateVideoAutoLoader(brigadeCode, cameraNum)) { while (!cts.IsCancellationRequested) { loader.Load(cts); await Task.Delay(Program.config.VideoAutoDelayMs, cts.Token); } } logger.Info($"Task [{brigadeCode}] autoupdate video was canseled"); }, cts.Token); t.Task.Start(); tasks.Add(t); } }
public void OnAutoload(int brigadeCode) { lock (tasksLock) { if (tasks.Any(x => x.BrigadeCode == brigadeCode)) { return; } var t = new AutoLoadChannelTask(); t.BrigadeCode = brigadeCode; var cts = new CancellationTokenSource(); t.Cts = cts; t.Task = new Task(async() => { logger.Info($"Task [{brigadeCode}] autoupdate channel was started"); using (var loader = AutoFileLoader.CreateChannelAutoLoader(brigadeCode)) { while (!cts.IsCancellationRequested) { loader.Load(cts); await Task.Delay(Program.config.ChannelAutoDelayMs, cts.Token); } } lock (tasksLock) { // Удаляем задачу из списка tasks.RemoveAll(x => x.BrigadeCode == brigadeCode); } logger.Info($"Task [{brigadeCode}] autoupdate channel was canseled"); }, cts.Token); tasks.Add(t); t.Task.Start(); } logger.Info($"{brigadeCode} [AUTO_CHANNEL_ON]"); }