Exemple #1
0
        public void Dispatch()
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            if (queue.AllCount > 0)
            {
                if (multiThreaded)
                {
                    foreach (var job in jobs)
                    {
                        job.JobException += (sender, e) => JobException?.Invoke(sender, e);
                        job.EmptyQueue   += balanceQueues;

                        job.Dispatch(queue);
                    }

                    WaitHandle.WaitAll(manualResetEvents);
                }
                else
                {
                    foreach (var job in jobs)
                    {
                        job.Execute(queue);
                    }
                }
            }

            stopwatch.Stop();
            Completed?.Invoke(this, new CompletedArgs(stopwatch.Elapsed));
        }
Exemple #2
0
 public void Execute(JobQueue queue)
 {
     while (queue.Dequeue(affinity).If(out var action))
     {
         try
         {
             action(affinity);
         }
         catch (Exception exception)
         {
             JobException?.Invoke(this, new JobExceptionArgs(affinity, exception));
         }
     }
 }
Exemple #3
0
        public void Dispatch(JobQueue queue)
        {
            manualResetEvent.Reset();

            var thread = new Thread(() =>
            {
                try
                {
                    var coreMask = getCoreMask(affinity);
                    setProcessorAffinity(coreMask);

                    while (true)
                    {
                        while (queue.Dequeue(affinity).If(out var action))
                        {
                            try
                            {
                                action(affinity);
                            }
                            catch (Exception exception)
                            {
                                JobException?.Invoke(this, new JobExceptionArgs(affinity, exception));
                            }

                            Thread.Sleep(500);
                        }

                        lock (locker)
                        {
                            var args = new JobEmptyQueueArgs(affinity);
                            EmptyQueue?.Invoke(this, args);
                            if (args.Quit)
                            {
                                break;
                            }
                        }
                    }
                }
                finally
                {
                    manualResetEvent.Set();
                }
            });

            thread.Start();
        }