private void WorkerThredStart(object sender, DoScheduledWorkEventArgs args)
        {
            Exception Error = null;

            try
            {
                if (CancellationPending)
                {
                    args.Cancel = true;
                }
                else
                {
                    OnDoWork(args);
                }
                if (args.Cancel)
                {
                    args.Result         = null;
                    cancellationPending = true;
                }
            }
            catch (Exception ex)
            {
                Error       = ex;
                args.Result = null;
            }
            mainThreadContext.Post(workCallback, new RunWorkerCompletedEventArgs(args.Result, Error, args.Cancel));
            mainThreadContext.OperationCompleted();
        }
        private void WorkerThreadStart(object sender, DoScheduledWorkEventArgs args)
        {
            Exception Error = null;

            try
            {
                if (CancellationPending)
                {
                    args.Cancel = true;
                }
                else
                {
                    OnDoWork(args);
                }
                if (args.Cancel)
                {
                    args.Result         = null;
                    cancellationPending = true;
                }
            }
            catch (Exception ex)
            {
                Error       = ex;
                args.Result = null;
            }
            finally
            {
                mainThreadOperation.Post(completedCallback, new RunWorkerCompletedEventArgs(args.Result, Error, args.Cancel));
                doNotDisposeWaitHandle.Set();
            }
        }
 protected void OnDoWork(DoScheduledWorkEventArgs args)
 {
     ((EventHandler <DoScheduledWorkEventArgs>)Events[doWorkKey])?.Invoke(this, args);
 }