/// <summary> /// Queues a method for execution. The method executes when this worker is ready. /// </summary> /// <param name="function">The work to execute asynchronously.</param> /// <param name="state">An object containing data to be used by the work.</param> public void Invoke(Func <object, Task> function, object state, InvokeOptions options = InvokeOptions.Normal, SyncOptions syncOptions = null) { if (syncOptions != null) { ValidateSyncOptions(syncOptions); } var work = new WorkFs { Function = function, State = state, Options = (WorkOptions)((int)options), Sync = syncOptions != null ? new WorkSyncContext(syncOptions) : null }; QueueWork(work); }
/// <summary> /// Queues the specified work to run when this worker is ready and returns a proxy for the task returned by function. /// </summary> /// <param name="function">The work to execute asynchronously.</param> /// <param name="state">An object containing data to be used by the work.</param> public Task <Task> InvokeAsync(Func <object, Task> function, object state, InvokeOptions options = InvokeOptions.Normal, SyncOptions syncOptions = null) { if (syncOptions != null) { ValidateSyncOptions(syncOptions); } var work = new WorkFs { Function = function, State = state, Options = (WorkOptions)((int)options), CompletionSource = new TaskCompletionSource <Task>(), Sync = syncOptions != null ? new WorkSyncContext(syncOptions) : null }; QueueWork(work); return(work.CompletionSource.Task); }