System.Threading.Timer.Dispose Method

Releases all resources used by the current instance of System.Threading.Timer and signals when the timer has been disposed of.

Syntax

public bool Dispose (WaitHandle notifyObject)

Parameters

notifyObject
The System.Threading.WaitHandle to be signaled when the Timer has been disposed of.

Returns

true if the function succeeds; otherwise, false.

Exceptions

TypeReason
ArgumentNullException notifyObject is null.

Remarks

Calling Dispose allows the resources used by the System.Threading.Timer to be reallocated for other purposes. For more information about Dispose, see [<topic://cpconCleaningUpUnmanagedResources>].

When this method completes, it signals the System.Threading.WaitHandle specified by the notifyObject parameter. Use this overload of the erload:System.Threading.Timer.Dispose method if you want to be able to block until you are certain that the timer has been disposed. The timer is not disposed until all currently queued callbacks have completed.

Note:

If the callback uses the erload:System.Threading.Timer.Change method to set the dueTime parameter to zero, a race condition can occur when the Timer.Dispose(WaitHandle) method overload is called: If the timer queues a new callback before the Timer.Dispose(WaitHandle) method overload detects that there are no callbacks queued, Timer.Dispose(WaitHandle) continues to block; otherwise, the timer is disposed while the new callback is being queued, and an ObjectDisposedException is thrown when the new callback calls the erload:System.Threading.Timer.Change method.

Requirements

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0