Compartilhar via


AsyncTask.ExecuteOnExecutor(IExecutor, Object[]) Method

Definition

Executes the task with the specified parameters.

[Android.Runtime.Register("executeOnExecutor", "(Ljava/util/concurrent/Executor;[Ljava/lang/Object;)Landroid/os/AsyncTask;", "")]
public Android.OS.AsyncTask? ExecuteOnExecutor (Java.Util.Concurrent.IExecutor? exec, params Java.Lang.Object[]? params);
[<Android.Runtime.Register("executeOnExecutor", "(Ljava/util/concurrent/Executor;[Ljava/lang/Object;)Landroid/os/AsyncTask;", "")>]
member this.ExecuteOnExecutor : Java.Util.Concurrent.IExecutor * Java.Lang.Object[] -> Android.OS.AsyncTask

Parameters

exec
IExecutor

The executor to use. #THREAD_POOL_EXECUTOR is available as a convenient process-wide thread pool for tasks that are loosely coupled.

params
Object[]

The parameters of the task.

Returns

This instance of AsyncTask.

Attributes

Remarks

Executes the task with the specified parameters. The task returns itself (this) so that the caller can keep a reference to it.

This method is typically used with #THREAD_POOL_EXECUTOR to allow multiple tasks to run in parallel on a pool of threads managed by AsyncTask, however you can also use your own Executor for custom behavior.

<em>Warning:</em> Allowing multiple tasks to run in parallel from a thread pool is generally <em>not</em> what one wants, because the order of their operation is not defined. For example, if these tasks are used to modify any state in common (such as writing a file due to a button click), there are no guarantees on the order of the modifications. Without careful work it is possible in rare cases for the newer version of the data to be over-written by an older one, leading to obscure data loss and stability issues. Such changes are best executed in serial; to guarantee such work is serialized regardless of platform version you can use this function with #SERIAL_EXECUTOR.

This method must be invoked on the UI thread.

Java documentation for android.os.AsyncTask.executeOnExecutor(java.util.concurrent.Executor, Params...).

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