Udostępnij za pośrednictwem


ForkJoinTask.Cancel(Boolean) Method

Definition

Attempts to cancel execution of this task.

[Android.Runtime.Register("cancel", "(Z)Z", "GetCancel_ZHandler")]
public virtual bool Cancel (bool mayInterruptIfRunning);
[<Android.Runtime.Register("cancel", "(Z)Z", "GetCancel_ZHandler")>]
abstract member Cancel : bool -> bool
override this.Cancel : bool -> bool

Parameters

mayInterruptIfRunning
Boolean

this value has no effect in the default implementation because interrupts are not used to control cancellation.

Returns

true if this task is now cancelled

Implements

Attributes

Remarks

Attempts to cancel execution of this task. This attempt will fail if the task has already completed or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, execution of this task is suppressed. After this method returns successfully, unless there is an intervening call to #reinitialize, subsequent calls to #isCancelled, #isDone, and cancel will return true and calls to #join and related methods will result in CancellationException.

This method may be overridden in subclasses, but if so, must still ensure that these properties hold. In particular, the cancel method itself must not throw exceptions.

This method is designed to be invoked by <em>other</em> tasks. To terminate the current task, you can just return or throw an unchecked exception from its computation method, or invoke #completeExceptionally(Throwable).

Java documentation for java.util.concurrent.ForkJoinTask.cancel(boolean).

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Applies to