I manage status, progress, and cancellation for long-running operations. Whoever initiates the operation should create a Monitor instance and pass it into the code that implements the operation. That code should periodically check in with the Monitor, perhaps after each major unit of work has been completed, for two purposes. The first is to inform the Monitor about progress that has been made, so that external observers can be reassured that the operation is proceeding normally. If the operation has a well-known amount of work to perform, this notification should reflect that, so that an ETA or 'percentage complete' value can be derived. The second purpose is to check to see if the operation has been cancelled. The impatient observer who no longer wants the operation to continue will inform the Monitor; the next time the operation code checks in, it should notice that the operation has been cancelled, and wrap things up. The same monitor can be passed to multiple operations, all of which may check for cancellation: this pattern may be simpler than having the original caller keep track of subtasks and cancel them individually.
Public Member Functions