DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
Task.h
Go to the documentation of this file.
1
3
4#pragma once
5
6#include "Common.h"
7#include "System/Object.h"
8#include "System/Action.h"
13
14namespace DotNetDupe {
15 namespace System {
16 namespace Threading {
17 namespace Tasks {
18
27 class Task : public Object {
28 public:
31 DOTNETDUPE_API Task(Action<> objAction);
32
34 DOTNETDUPE_API virtual ~Task();
35
37 DOTNETDUPE_API void Start();
38
40 DOTNETDUPE_API void Wait();
41
45 DOTNETDUPE_API bool Wait(int iMillisecondsTimeout);
46
50
53 DOTNETDUPE_API bool GetIsCompleted() const;
54
57 DOTNETDUPE_API bool GetIsFaulted() const;
58
61 DOTNETDUPE_API bool GetIsCanceled() const;
62
67
68 private:
69 Action<> m_objAction;
70 TaskStatus m_eStatus;
71 SmartPointer<ManualResetEvent> m_pCompletionEvent = nullptr;
72 mutable CriticalSection m_csSync;
73
74 void Execute();
75 static void ThreadPoolCallback(Object* pState);
76
77 static void RetainTask(SmartPointer<Task> pTask);
78 static void ReleaseTask(Task* pTask);
79 };
80
81 }
82 }
83 }
84}
Encapsulates a delegate method that has parameters and returns void.
Defines common cross-platform macros, export decorators, and fundamental types.
#define DOTNETDUPE_API
Platform-specific linkage decoration for exporting or importing library symbols.
Definition Common.h:20
Provides a re-entrant mutual exclusion primitive for thread synchronization.
Notifies one or more waiting threads that an event has occurred.
Base object class for DotNetDupe mirroring .NET System.Object.
Provides reference-counted and weak pointer memory management primitives ensuring zero raw ownership.
Represents the current stage in the lifecycle of an asynchronous Task.
Supports all classes in the DotNetDupe class hierarchy.
Definition Object.h:18
A unified smart pointer that supports both unique and shared ownership semantics.
Provides a re-entrant mutual exclusion primitive for thread synchronization.
void Wait()
Waits indefinitely for the Task to complete execution.
Definition Task.cpp:43
bool GetIsCompleted() const
Gets whether this Task has completed.
Definition Task.cpp:63
Task(Action<> objAction)
Initializes a new Task with the specified action delegate.
Definition Task.cpp:19
bool GetIsCanceled() const
Gets whether this Task instance has completed execution due to being canceled.
Definition Task.cpp:77
static SmartPointer< Task > Run(Action<> objAction)
Queues the specified work to run on the ThreadPool and returns a Task representing that work.
Definition Task.cpp:83
void Start()
Starts the Task, scheduling it for execution to the ThreadPool.
Definition Task.cpp:29
TaskStatus GetStatus() const
Gets the TaskStatus of this task.
Definition Task.cpp:57
bool GetIsFaulted() const
Gets whether the Task completed due to an unhandled exception.
Definition Task.cpp:71
TaskStatus
Represents the current stage in the lifecycle of a Task.
Definition TaskStatus.h:12