public static void Main() { string _sAction = ConfigurationManager.AppSettings["action"]; string _sSeparetion = ConfigurationManager.AppSettings["charsplit"]; string[] paths = _sAction.Split(_sSeparetion); if (paths.Length < 3) { _sAction = _sAction + _sSeparetion + _sSeparetion + _sSeparetion + _sSeparetion; paths = _sAction.Split(_sSeparetion); } long[] result = new long[4]; #region ParallelTasks // Perform three tasks in parallel on the source array Parallel.Invoke(() => { WorkerRun work = new WorkerRun(new Logging(), "#1"); result[0] = work.Go("Start Cleaning Task", ""); }, () => { WorkerRun work = new WorkerRun(new Logging(), "#2"); result[1] = work.Go("Start Explorer Task", paths[0]); }, // close first Action () => { WorkerRun work = new WorkerRun(new Logging(), "#3"); result[2] = work.Go("Start Explorer Task", paths[1]); }, //close second Action () => { WorkerRun work = new WorkerRun(new Logging(), "#4"); result[3] = work.Go("Start Explorer Task", paths[2]); } //close third Action ); //close parallel.invoke Console.WriteLine(string.Format("Returned from Parallel.Invoke; [return Task 1 = {0} - return Task 2 = {1} - return Task 3 = {2} - return Task 4 = {3}]", result[0], result[1], result[2], result[3])); #endregion Console.WriteLine("Press any key to exit"); Console.ReadKey(); }
public async Task <int> RunAsync(Type workerType, object data) { var workerInfo = await _workerInfoRepository.GetEntities() .FirstOrDefaultAsync(e => e.ClassName == workerType.FullName); if (workerInfo == null) { throw new ServiceException($"{workerType.Name} not found"); } var workerRun = new WorkerRun { WorkerInfoId = workerInfo.Id, Data = data != null?JsonSerializer.Serialize(data) : null, }; _workerRunRepository.Add(workerRun); await _unitOfWork.CommitAsync(); await _messagingService.SendAsync(StartWorkerRun.QueueName, new StartWorkerRun(workerRun.Id)); return(workerRun.Id); }