20 : m_objAction(objAction), m_eStatus(
TaskStatus::Created) {
45 m_pCompletionEvent->WaitOne();
51 return m_pCompletionEvent->WaitOne(iMillisecondsTimeout);
91 void Task::Execute() {
98 if (m_objAction) m_objAction();
102 Lock<CriticalSection> lock(m_csSync);
106 m_pCompletionEvent->Set();
110 void Task::ThreadPoolCallback(Object* pState) {
112 Task* pTask =
static_cast<Task*
>(pState);
113 if (pTask ==
nullptr)
return;
116 SmartPointer<Task> spSelf(
nullptr);
128 if (!spSelf.IsNull()) {
133 void Task::RetainTask(SmartPointer<Task> pTask) {
139 void Task::ReleaseTask(
Task* pTask) {
Defines the exception thrown when a method call is invalid for the object's current state.
Represents a strongly typed list of objects that can be accessed by index mirroring ....
Provides an RAII-style scoped lock wrapper around synchronization primitives.
Serves as the base class for system exceptions across the library.
Represents an asynchronous operation mirroring .NET System.Threading.Tasks.Task.
Provides a pool of threads that can be used to execute tasks and work items.
Defines the exception thrown when the time allotted for a process or operation has expired.
Represents an unknown or unmapped exception encountered during execution.
Represents a strongly typed list of objects accessible by index.
InvalidOperationException(const String &sMessage)
Initializes a new instance of the InvalidOperationException class with a specified error message.
A unified smart pointer that supports both unique and shared ownership semantics.
static SmartPointer< T > NewShared()
Creates a Shared SmartPointer, default constructing T.
Provides a re-entrant mutual exclusion primitive for thread synchronization.
Provides an RAII-style scoped lock wrapper around synchronization primitives.
Represents an asynchronous operation.
virtual ~Task()
Destructor for Task.
void Wait()
Waits indefinitely for the Task to complete execution.
bool GetIsCompleted() const
Gets whether this Task has completed.
Task(Action<> objAction)
Initializes a new Task with the specified action delegate.
bool GetIsCanceled() const
Gets whether this Task instance has completed execution due to being canceled.
static SmartPointer< Task > Run(Action<> objAction)
Queues the specified work to run on the ThreadPool and returns a Task representing that work.
void Start()
Starts the Task, scheduling it for execution to the ThreadPool.
TaskStatus GetStatus() const
Gets the TaskStatus of this task.
bool GetIsFaulted() const
Gets whether the Task completed due to an unhandled exception.
static bool QueueUserWorkItem(WaitCallback callback)
Queues a method for execution. The method executes when a thread pool thread becomes available.
The exception that is thrown when the time allotted for a process or operation has expired.
TaskStatus
Represents the current stage in the lifecycle of a Task.
static CriticalSection s_csActiveTasks
static Collections::Generic::List< SmartPointer< Task > > s_pvActiveTasks