description | title | ms.date | ms.topic | f1_keywords | helpviewer_keywords | ms.assetid | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Learn more about: AsyncBase Class |
AsyncBase Class |
10/08/2018 |
reference |
|
|
64259b9b-f427-4ffd-a611-e7a2f82362b2 |
Implements the Windows Runtime asynchronous state machine.
template <
typename TComplete,
typename TProgress = Details::Nil,
AsyncResultType resultType = SingleResult
>
class AsyncBase : public AsyncBase<TComplete, Details::Nil, resultType>;
template <typename TComplete, AsyncResultType resultType>
class AsyncBase<TComplete, Details::Nil, resultType> :
public Microsoft::WRL::Implements<IAsyncInfo>;
TComplete
An event handler that is called when an asynchronous operation completes.
TProgress
An event handler that is called when a running asynchronous operation reports the current progress of the operation.
resultType
One of the AsyncResultType enumeration values. By default, SingleResult
.
Name | Description |
---|---|
AsyncBase::AsyncBase | Initializes an instance of the AsyncBase class. |
Name | Description |
---|---|
AsyncBase::Cancel | Cancels an asynchronous operation. |
AsyncBase::Close | Closes the asynchronous operation. |
AsyncBase::FireCompletion | Invokes the completion event handler, or resets the internal progress delegate. |
AsyncBase::FireProgress | Invokes the current progress event handler. |
AsyncBase::get_ErrorCode | Retrieves the error code for the current asynchronous operation. |
AsyncBase::get_Id | Retrieves the handle of the asynchronous operation. |
AsyncBase::get_Status | Retrieves a value that indicates the status of the asynchronous operation. |
AsyncBase::GetOnComplete | Copies the address of the current completion event handler to the specified variable. |
AsyncBase::GetOnProgress | Copies the address of the current progress event handler to the specified variable. |
AsyncBase::put_Id | Sets the handle of the asynchronous operation. |
AsyncBase::PutOnComplete | Sets the address of the completion event handler to the specified value. |
AsyncBase::PutOnProgress | Sets the address of the progress event handler to the specified value. |
Name | Description |
---|---|
AsyncBase::CheckValidStateForDelegateCall | Tests whether delegate properties can be modified in the current asynchronous state. |
AsyncBase::CheckValidStateForResultsCall | Tests whether the results of an asynchronous operation can be collected in the current asynchronous state. |
AsyncBase::ContinueAsyncOperation | Determines whether the asynchronous operation should continue processing or should halt. |
AsyncBase::CurrentStatus | Retrieves the status of the current asynchronous operation. |
AsyncBase::ErrorCode | Retrieves the error code for the current asynchronous operation. |
AsyncBase::OnCancel | When overridden in a derived class, cancels an asynchronous operation. |
AsyncBase::OnClose | When overridden in a derived class, closes an asynchronous operation. |
AsyncBase::OnStart | When overridden in a derived class, starts an asynchronous operation. |
AsyncBase::Start | Starts the asynchronous operation. |
AsyncBase::TryTransitionToCompleted | Indicates whether the current asynchronous operation has completed. |
AsyncBase::TryTransitionToError | Indicates whether the specified error code can modify the internal error state. |
AsyncBase
AsyncBase
Header: async.h
Namespace: Microsoft::WRL
Initializes an instance of the AsyncBase
class.
AsyncBase();
Cancels an asynchronous operation.
STDMETHOD(
Cancel
)(void);
By default, always returns S_OK.
Cancel()
is a default implementation of IAsyncInfo::Cancel
, and does no actual work. To actually cancel an asynchronous operation, override the OnCancel()
pure virtual method.
Tests whether delegate properties can be modified in the current asynchronous state.
inline HRESULT CheckValidStateForDelegateCall();
S_OK if delegate properties can be modified; otherwise, E_ILLEGAL_METHOD_CALL.
Tests whether the results of an asynchronous operation can be collected in the current asynchronous state.
inline HRESULT CheckValidStateForResultsCall();
S_OK if results can be collected; otherwise, E_ILLEGAL_METHOD_CALLE_ILLEGAL_METHOD_CALL.
Closes the asynchronous operation.
STDMETHOD(
Close
)(void) override;
S_OK if the operation closes or is already closed; otherwise, E_ILLEGAL_STATE_CHANGE.
Close()
is a default implementation of IAsyncInfo::Close
, and does no actual work. To actually close an asynchronous operation, override the OnClose()
pure virtual method.
Determines whether the asynchronous operation should continue processing or should halt.
inline bool ContinueAsyncOperation();
true
if the current state of the asynchronous operation is started, which means the operation should continue. Otherwise, false
, which means the operation should halt.
Retrieves the status of the current asynchronous operation.
inline void CurrentStatus(
Details::AsyncStatusInternal *status
);
status
The location where this operation stores the current status.
This operation is thread-safe.
Retrieves the error code for the current asynchronous operation.
inline void ErrorCode(
HRESULT *error
);
error
The location where this operation stores the current error code.
This operation is thread-safe.
Invokes the completion event handler, or resets the internal progress delegate.
void FireCompletion(
void
) override;
virtual void FireCompletion();
The first version of FireCompletion()
resets the internal progress delegate variable. The second version invokes the completion event handler if the asynchronous operation is complete.
Invokes the current progress event handler.
void FireProgress(
const typename ProgressTraits::Arg2Type arg
);
arg
The event handler method to invoke.
ProgressTraits
is derived from ArgTraitsHelper Structure.
Retrieves the error code for the current asynchronous operation.
STDMETHOD(
get_ErrorCode
)(HRESULT* errorCode) override;
errorCode
The location where the current error code is stored.
S_OK if successful; otherwise, E_ILLEGAL_METHOD_CALL if the current asynchronous operation is closed.
Retrieves the handle of the asynchronous operation.
STDMETHOD(
get_Id
)(unsigned int *id) override;
id
The location where the handle is to be stored.
S_OK if successful; otherwise, E_ILLEGAL_METHOD_CALL.
This method implements IAsyncInfo::get_Id
.
Retrieves a value that indicates the status of the asynchronous operation.
STDMETHOD(
get_Status
)(AsyncStatus *status) override;
status
The location where the status is to be stored. For more information, see Windows::Foundation::AsyncStatus
enumeration.
S_OK if successful; otherwise, E_ILLEGAL_METHOD_CALL.
This method implements IAsyncInfo::get_Status
.
Copies the address of the current completion event handler to the specified variable.
STDMETHOD(
GetOnComplete
)(TComplete** completeHandler);
completeHandler
The location where the address of the current completion event handler is stored.
S_OK if successful; otherwise, E_ILLEGAL_METHOD_CALL.
Copies the address of the current progress event handler to the specified variable.
STDMETHOD(
GetOnProgress
)(TProgress** progressHandler);
progressHandler
The location where the address of the current progress event handler is stored.
S_OK if successful; otherwise, E_ILLEGAL_METHOD_CALL.
When overridden in a derived class, cancels an asynchronous operation.
virtual void OnCancel(
void
) = 0;
When overridden in a derived class, closes an asynchronous operation.
virtual void OnClose(
void
) = 0;
When overridden in a derived class, starts an asynchronous operation.
virtual HRESULT OnStart(
void
) = 0;
Sets the handle of the asynchronous operation.
STDMETHOD(
put_Id
)(const unsigned int id);
id
A nonzero handle.
S_OK if successful; otherwise, E_INVALIDARG or E_ILLEGAL_METHOD_CALL.
Sets the address of the completion event handler to the specified value.
STDMETHOD(
PutOnComplete
)(TComplete* completeHandler);
completeHandler
The address to which the completion event handler is set.
S_OK if successful; otherwise, E_ILLEGAL_METHOD_CALL.
Sets the address of the progress event handler to the specified value.
STDMETHOD(
PutOnProgress
)(TProgress* progressHandler);
progressHandler
The address to which the progress event handler is set.
S_OK if successful; otherwise, E_ILLEGAL_METHOD_CALL.
Starts the asynchronous operation.
STDMETHOD(
Start
)(void);
S_OK if the operation starts or is already started; otherwise, E_ILLEGAL_STATE_CHANGE.
Start()
is a protected method that is not externally visible because async operations "hot start" before returning to the caller.
Indicates whether the current asynchronous operation has completed.
bool TryTransitionToCompleted(
void
);
true
if the asynchronous operation has completed; otherwise, false
.
Indicates whether the specified error code can modify the internal error state.
bool TryTransitionToError(
const HRESULT error
);
error
An error HRESULT.
true
if the internal error state was changed; otherwise, false
.
This operation modifies the error state only if the error state is already set to S_OK. This operation has no effect if the error state is already error, cancelled, completed, or closed.