Method RefreshAsync
RefreshAsync(bool, CancellationToken)
Asynchronously forces a refresh of the current image, performing detection and updating the capture to the latest state.
Declaration
Task<WindowImageProcessedEventArgs<TDetectionResult>> RefreshAsync(bool includeImages = false, CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
bool | includeImages | Indicates whether images should be included in the detection results. |
CancellationToken | cancellationToken | A token to monitor for cancellation requests, allowing the operation to be canceled if necessary. |
Returns
Type | Description |
---|---|
Task<WindowImageProcessedEventArgs<TDetectionResult>> | A task representing the asynchronous operation, containing the detection results as WindowImageProcessedEventArgs<TDetectionResult>. |
Remarks
The RefreshAsync(bool, CancellationToken) method is the preferred approach for refreshing and detecting images due to its asynchronous nature, which allows for non-blocking operations and improved application responsiveness.
Similar to the Refresh(bool, CancellationToken) method, this asynchronous version carries out the following operations:
- Retrieval of the latest image from the source.
- Execution of the detection process.
- Application of trigger conditions.
- Provision of detection results to the caller.
Important considerations:
- The images are live references, updated by the system, and should be handled in a thread-safe manner in-place.
- Images are not included by default in the result to optimize performance; control this behavior with
includeImages
. - Errors are propagated to the caller, including those that might occur due to cancellation.
Usage of this method with await
ensures that the calling thread is not blocked, which is especially beneficial in UI applications where maintaining responsiveness is crucial.
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Thrown if the operation is canceled via the |
Exception | Other exceptions may be thrown if an error occurs during the detection process. |
RefreshAsync(CancellationToken)
Asynchronously forces a refresh of the current image, performing detection and updating the capture to the latest state.
Declaration
Task<WindowImageProcessedEventArgs<TDetectionResult>> RefreshAsync(CancellationToken cancellationToken = default)
Parameters
Type | Name | Description |
---|---|---|
CancellationToken | cancellationToken | A token to monitor for cancellation requests, allowing the operation to be canceled if necessary. |
Returns
Type | Description |
---|---|
Task<WindowImageProcessedEventArgs<TDetectionResult>> | A task representing the asynchronous operation, containing the detection results as WindowImageProcessedEventArgs<TDetectionResult>. |
Remarks
The RefreshAsync(bool, CancellationToken) method is the preferred approach for refreshing and detecting images due to its asynchronous nature, which allows for non-blocking operations and improved application responsiveness.
Similar to the Refresh(bool, CancellationToken) method, this asynchronous version carries out the following operations:
- Retrieval of the latest image from the source.
- Execution of the detection process.
- Application of trigger conditions.
- Provision of detection results to the caller.
Important considerations:
- Errors are propagated to the caller, including those that might occur due to cancellation.
Usage of this method with await
ensures that the calling thread is not blocked, which is especially beneficial in UI applications where maintaining responsiveness is crucial.
Exceptions
Type | Condition |
---|---|
OperationCanceledException | Thrown if the operation is canceled via the |
Exception | Other exceptions may be thrown if an error occurs during the detection process. |