/// <inheritdoc />
        public virtual void Initialize(WorkerExecutionContext context)
        {
            lock (syncRoot)
            {
                GuardMustNotBeDisposed();
                GuardMustNotBeRunning();
                GuardMustNotBeInitialized();

                runTask = new Task(() => OnRun(context), DetermineCreationOptions(context));
                if (context.PostCompletedCallback != null)
                {
                    postCompletionTask = runTask.ContinueWith((t1, state) => OnPostCompleted(context), null);
                }

                Initialized = true;
            }
        }
 /// <summary>
 /// Occurs when the worker has completed.
 /// </summary>
 /// <param name="context">The object containing contextual information about the worker.</param>
 protected virtual void OnPostCompleted(WorkerExecutionContext context)
 {
     context.PostCompletedCallback?.Invoke();
 }
 /// <summary>
 /// Occurs when the worker runs.
 /// </summary>
 /// <param name="context">The object containing contextual information about the worker.</param>
 protected virtual void OnRun(WorkerExecutionContext context)
 {
     context.OnRunCallback?.Invoke();
 }
 /// <summary>
 /// Determines the creation options for the task.
 /// </summary>
 /// <param name="context">The object containing contextual information for the worker execution.</param>
 /// <returns>The task creation options for the new task.</returns>
 protected virtual TaskCreationOptions DetermineCreationOptions(WorkerExecutionContext context)
 {
     return(TaskCreationOptions.None);
 }