Ejemplo n.º 1
0
        private void ExecuteLoop()
        {
            var token = cancelTokenSource.Token;

            while (!token.IsCancellationRequested)
            {
                ExecuteInfo?task;
                do
                {
                    task = taskSource.GetTask(executorID);
                    if (task.HasValue)
                    {
                        try { task.Value.Execute(executorID); }
                        catch (Exception) { }
                    }
                } while(task.HasValue);

                //No tasks left, go to sleep and wait to be woken
                try
                {
                    wakeEvent.Wait(token);
                }
                catch (OperationCanceledException)
                {
                    break;
                }
                wakeEvent.Reset();
            }
        }
Ejemplo n.º 2
0
        private void ExecuteLoop()
        {
            var token = cancelTokenSource.Token;

            while (!token.IsCancellationRequested)
            {
                ExecuteInfo?task;
                do
                {
                    task = taskSource.GetTask(executorId);
                    if (task.HasValue)
                    {
                        try { task.Value.Execute(); }
                        catch (Exception e) { logger?.Log(nameof(ExecutorThread), $"Task exception: {e.Message}"); }
                    }
                } while (task.HasValue);

                //No tasks left, go to sleep and wait to be woken
                wakeEvent.Wait();
                wakeEvent.Reset();
            }
        }