C# Класс ANHAdmin.AsyncOperation

This base class is designed to be used by lengthy operations that wish to support cancellation. It also allows those operations to invoke delegates on the UI Thread of a hosting control.
This class is from the MSDN article: http://msdn.microsoft.com/msdnmag/issues/03/02/Multithreading/default.aspx (C) 2001-2002 I D Griffiths Please see the article for a complete description of the intentions and operation of this class.
Показать файл Открыть проект

Открытые методы

Метод Описание
AsyncOperation ( ISynchronizeInvoke target ) : System

Initialises an AsyncOperation with an association to the supplied ISynchronizeInvoke. All events raised from this object will be delivered via this target. (This might be a Control object, so events would be delivered to that Control's UI thread.)

Cancel ( ) : void

Attempt to cancel the current operation. This returns immediately to the caller. No guarantee is made as to whether the operation will be successfully cancelled. All that can be known is that at some point, one of the three events Completed, Cancelled, or Failed will be raised at some point.

CancelAndWait ( ) : bool

Attempt to cancel the current operation and block until either the cancellation succeeds or the operation completes.

Start ( ) : void

Launch the operation on a worker thread. This method will return immediately, and the operation will start asynchronously on a worker thread.

WaitUntilDone ( ) : bool

Blocks until the operation has either run to completion, or has been successfully cancelled, or has failed with an internal exception.

Защищенные методы

Метод Описание
AcknowledgeCancel ( ) : void

This is called by the operation when it wants to indicate that it saw the cancellation request and honoured it.

DoWork ( ) : void

To be overridden by the deriving class - this is where the work will be done. The base class calls this method on a worker thread when the Start method is called.

FireAsync ( Delegate dlg ) : void

Utility function for firing an event through the target. It uses C#'s variable length parameter list support to build the parameter list. This functions presumes that the caller holds the object lock. (This is because the event list is typically modified on the UI thread, but events are usually raised on the worker thread.)

Приватные методы

Метод Описание
CompleteOperation ( ) : void
FailOperation ( Exception e ) : void

InternalStart ( ) : void

Описание методов

AcknowledgeCancel() защищенный Метод

This is called by the operation when it wants to indicate that it saw the cancellation request and honoured it.
protected AcknowledgeCancel ( ) : void
Результат void

AsyncOperation() публичный Метод

Initialises an AsyncOperation with an association to the supplied ISynchronizeInvoke. All events raised from this object will be delivered via this target. (This might be a Control object, so events would be delivered to that Control's UI thread.)
public AsyncOperation ( ISynchronizeInvoke target ) : System
target ISynchronizeInvoke An object implementing the /// ISynchronizeInvoke interface. All events will be delivered /// through this target, ensuring that they are delivered to the /// correct thread.
Результат System

Cancel() публичный Метод

Attempt to cancel the current operation. This returns immediately to the caller. No guarantee is made as to whether the operation will be successfully cancelled. All that can be known is that at some point, one of the three events Completed, Cancelled, or Failed will be raised at some point.
public Cancel ( ) : void
Результат void

CancelAndWait() публичный Метод

Attempt to cancel the current operation and block until either the cancellation succeeds or the operation completes.
public CancelAndWait ( ) : bool
Результат bool

DoWork() защищенный абстрактный Метод

To be overridden by the deriving class - this is where the work will be done. The base class calls this method on a worker thread when the Start method is called.
protected abstract DoWork ( ) : void
Результат void

FireAsync() защищенный Метод

Utility function for firing an event through the target. It uses C#'s variable length parameter list support to build the parameter list. This functions presumes that the caller holds the object lock. (This is because the event list is typically modified on the UI thread, but events are usually raised on the worker thread.)
protected FireAsync ( Delegate dlg ) : void
dlg System.Delegate
Результат void

Start() публичный Метод

Launch the operation on a worker thread. This method will return immediately, and the operation will start asynchronously on a worker thread.
public Start ( ) : void
Результат void

WaitUntilDone() публичный Метод

Blocks until the operation has either run to completion, or has been successfully cancelled, or has failed with an internal exception.
public WaitUntilDone ( ) : bool
Результат bool