/// <summary>Creates a task (using the specified options) that is run after all the given tasks are completed.</summary> /// <param name="context">[in] Where to run this task.</param> /// <param name="dwTasks">[in] The number of tasks to wait.</param> /// <param name="dependentTasks">[in] An array of tasks to wait.</param> /// <param name="options">[in] The continuation options set for the task.</param> /// <param name="taskBody">[in] Worker method for the task.</param> /// <param name="asyncState">[in] Asynchronous state for the task.</param> /// <returns>The created task that runs after all of the other tasks have completed.</returns> public IVsTask ContinueWhenAllCompletedEx( uint context, uint dwTasks, IVsTask[] dependentTasks, uint options, IVsTaskBody taskBody, object asyncState) { var cancellationTokenSource = new CancellationTokenSource(); Task <object> waitTask = Task.Factory.StartNew <object>( () => { foreach (IVsTask dependentTask in dependentTasks) { dependentTask.Wait(); } return(null); }, cancellationTokenSource.Token, TaskCreationOptions.None, TaskScheduler.Default); return(new FakeIVsTask(waitTask, cancellationTokenSource).ContinueWithEx( context, options, taskBody, asyncState)); }
/// <summary>Appends the provided action (using the specified options) to this task to be run after the task is run to completion. The action is invoked on the context provided.</summary> /// <param name="context">[in] Where to run this task. Values are from <see cref="T:Microsoft.VisualStudio.Shell.Interop.__VSTASKRUNCONTEXT" />.</param> /// <param name="options">[in] Allows setting task continuation options. Values are from <see cref="T:Microsoft.VisualStudio.Shell.Interop.__VSTASKCONTINUATIONOPTIONS" />.</param> /// <param name="pTaskBody">[in] Action to be executed.</param> /// <param name="pAsyncState">[in] The asynchronous state of the task.</param> /// <returns>A new <see cref="T:Microsoft.VisualStudio.Shell.Interop.IVsTask" /> instance that has the current task as its parent.</returns> public IVsTask ContinueWithEx(uint context, uint options, IVsTaskBody pTaskBody, object pAsyncState) => new FakeIVsTask( this, (__VSTASKRUNCONTEXT)context, (__VSTASKCONTINUATIONOPTIONS)options, pTaskBody, pAsyncState);
public IVsTask ContinueWhenAllCompleted( uint context, uint tasks, IVsTask[] dependentTasks, IVsTaskBody taskBody) { return(CurrentService.ContinueWhenAllCompleted(context, tasks, dependentTasks, taskBody)); }
IVsTask IVsTaskSchedulerService.CreateTaskEx(uint context, uint options, IVsTaskBody taskBody, object asyncState) { return new VsTask(this, (VsTaskRunContext)context, () => { object result; taskBody.DoWork(null, 0, null, out result); return result; }); }
public IVsTask ContinueWith(uint context, IVsTaskBody taskBody) { if (!this.IsCompleted) { this.Start(); } return(this.ContinueWithEx(context, 0, taskBody, this.AsyncState)); }
IVsTask IVsTaskSchedulerService.CreateTaskEx(uint context, uint options, IVsTaskBody taskBody, object asyncState) { return(new VsTask(this, (VsTaskRunContext)context, () => { object result; taskBody.DoWork(null, 0, null, out result); return result; })); }
/// <summary> /// Executes a non-cancellable operation in the specified <see cref="VsTaskRunContext"/> and doesn't wait until it is completed /// </summary> /// <param name="serviceProvider">An instance of <see cref="IServiceProvider"/>. Required.</param> /// <param name="context">The <see cref="VsTaskRunContext"/> in which to run the operation</param> /// <param name="op">The operation to run</param> internal static void BeginTask(IServiceProvider serviceProvider, VsTaskRunContext context, Action op) { Debug.Assert(serviceProvider != null, "IServiceProvider is required"); Debug.Assert(op != null, "Action is required"); IVsTaskSchedulerService taskService = serviceProvider.GetService(typeof(SVsTaskSchedulerService)) as IVsTaskSchedulerService; IVsTaskBody body = VsTaskLibraryHelper.CreateTaskBody(op); IVsTask task = VsTaskLibraryHelper.CreateTask(taskService, context, VsTaskCreationOptions.NotCancelable, body, null); task.Start(); }
public IVsTask ContinueWithEx(uint context, uint options, IVsTaskBody taskBody, object asyncState) { VsTask continuation = new VsTask(this.owner, (VsTaskRunContext)context, () => { object taskBodyResult; taskBody.DoWork(null, 0, null, out taskBodyResult); return(taskBodyResult); }); continuation.Start(); return(continuation); }
IVsTask IVsTaskSchedulerService.ContinueWhenAllCompletedEx(uint context, uint tasks, IVsTask[] dependentTasks, uint options, IVsTaskBody taskBody, object asyncState) { foreach (IVsTask t in dependentTasks) { if (!t.IsCompleted) { t.Start(); } } IVsTask task = ((IVsTaskSchedulerService)this).CreateTask(context, taskBody); task.Start(); return task; }
public IVsTask ContinueWhenAllCompletedEx( uint context, uint tasks, IVsTask[] dependentTasks, uint options, IVsTaskBody taskBody, object asyncState) { return(CurrentService.ContinueWhenAllCompletedEx( context, tasks, dependentTasks, options, taskBody, asyncState)); }
/// <summary> /// Creates a <see cref="IVsTask"/> in the specified <see cref="VsTaskRunContext"/> /// </summary> /// <param name="serviceProvider">An instance of <see cref="IServiceProvider"/>. Required.</param> /// <param name="context">The <see cref="VsTaskRunContext"/> in which to run the operation</param> /// <param name="op">The operation to run</param> /// <param name="token">Option cancellation token <see cref="CancellationToken"/></param> /// <returns>An await-able object that returns a result</returns> private static IVsTask CreateTask <T>(IServiceProvider serviceProvider, VsTaskRunContext context, Func <T> op, CancellationToken token) { Debug.Assert(serviceProvider != null, "IServiceProvider is required"); Debug.Assert(op != null, "op is required"); IVsTaskSchedulerService taskService = serviceProvider.GetService(typeof(SVsTaskSchedulerService)) as IVsTaskSchedulerService; IVsTaskBody body = VsTaskLibraryHelper.CreateTaskBody(() => (object)op()); IVsTask task = VsTaskLibraryHelper.CreateTask(taskService, context, body); if (token != CancellationToken.None) { task.ApplyCancellationToken(token); } return(task); }
/// <inheritdoc /> public IVsTask ContinueWithEx(uint context, uint options, IVsTaskBody pTaskBody, object?pAsyncState) { // NOTE: We ignore options (and context), if any tests are testing code that relies on either this // would need to be modified to properly support them. return(new MockVSTask( this.vsTaskSchedulerService2, context, this.task.ContinueWith( t => { pTaskBody.DoWork(this, 0, Array.Empty <IVsTask>(), out object result); return result; }, this.cancellationTokenSource.Token, TaskContinuationOptions.None, (TaskScheduler)this.vsTaskSchedulerService2.GetTaskScheduler(context)), pAsyncState)); }
private FakeIVsTask( FakeIVsTask parent, __VSTASKRUNCONTEXT context, __VSTASKCONTINUATIONOPTIONS options, IVsTaskBody body, object asyncState) { TaskScheduler scheduler = GetSchedulerFromContext(context); TaskContinuationOptions continuationOptions = GetTaskContinuationOptions(options); _t = parent._t.ContinueWith( (task, state) => { body.DoWork(this, 1, new IVsTask[] { parent }, out object result); return(result); }, asyncState, default(CancellationToken), continuationOptions, scheduler); parent.OnMarkedAsBlocking?.Invoke(parent, new BlockingTaskEventArgs(parent, this)); }
IVsTask IVsTaskSchedulerService.CreateTask(uint context, IVsTaskBody taskBody) { return(((IVsTaskSchedulerService)this).CreateTaskEx(context, 0, taskBody, null)); }
IVsTask IVsTaskSchedulerService.ContinueWhenAllCompleted(uint context, uint tasks, IVsTask[] dependentTasks, IVsTaskBody taskBody) { return(((IVsTaskSchedulerService)this).ContinueWhenAllCompletedEx(context, tasks, dependentTasks, 0, taskBody, null)); }
IVsTask IVsTaskSchedulerService.ContinueWhenAllCompletedEx(uint context, uint tasks, IVsTask[] dependentTasks, uint options, IVsTaskBody taskBody, object asyncState) { foreach (IVsTask t in dependentTasks) { if (!t.IsCompleted) { t.Start(); } } IVsTask task = ((IVsTaskSchedulerService)this).CreateTask(context, taskBody); task.Start(); return(task); }
public IVsTask CreateTaskEx(uint context, uint options, IVsTaskBody taskBody, object asyncState) => CurrentService.CreateTaskEx(context, options, taskBody, asyncState);
public IVsTask CreateTask(uint context, IVsTaskBody taskBody) => CurrentService.CreateTask(context, taskBody);
IVsTask IVsTaskSchedulerService.CreateTask(uint context, IVsTaskBody taskBody) { return ((IVsTaskSchedulerService)this).CreateTaskEx(context, 0, taskBody, null); }
/// <summary>Creates a task that is run on the given context.</summary> /// <param name="context">[in] Where to run this task. Values are from <see cref="T:Microsoft.VisualStudio.Shell.Interop.__VSTASKRUNCONTEXT" />.</param> /// <param name="taskBody">[in] Action to be executed.</param> /// <returns>The task to be run.</returns> public IVsTask CreateTask(uint context, IVsTaskBody taskBody) => new FakeIVsTask(Task.FromResult(new object())).ContinueWith(context, taskBody);
IVsTask IVsTaskSchedulerService.ContinueWhenAllCompleted(uint context, uint tasks, IVsTask[] dependentTasks, IVsTaskBody taskBody) { return ((IVsTaskSchedulerService)this).ContinueWhenAllCompletedEx(context, tasks, dependentTasks, 0, taskBody, null); }
/// <summary>Creates a task with the specified options that is run on the given context.</summary> /// <param name="context">[in] Where to run this task. Values are from <see cref="T:Microsoft.VisualStudio.Shell.Interop.__VSTASKRUNCONTEXT" />.</param> /// <param name="options">[in] The creation options set for the task. Values are from <see cref="T:Microsoft.VisualStudio.Shell.Interop.__VSTASKCREATIONOPTIONS" />.</param> /// <param name="taskBody">[in] Action to be executed.</param> /// <param name="asyncState">[in] The asynchronous state of the task.</param> /// <returns>The new task instance.</returns> public IVsTask CreateTaskEx(uint context, uint options, IVsTaskBody taskBody, object asyncState) => new FakeIVsTask(Task.FromResult(new object())).ContinueWithEx(context, options, taskBody, asyncState);
public IVsTask ContinueWithEx(uint context, uint options, IVsTaskBody taskBody, object asyncState) { VsTask continuation = new VsTask(this.owner, (VsTaskRunContext)context, () => { object taskBodyResult; taskBody.DoWork(null, 0, null, out taskBodyResult); return taskBodyResult; }); continuation.Start(); return continuation; }
/// <summary>Appends the provided action to this task to be run after the task is run to completion. The action is invoked on the context provided.</summary> /// <param name="context">[in] Where to run this task. Values are from <see cref="T:Microsoft.VisualStudio.Shell.Interop.__VSTASKRUNCONTEXT" />.</param> /// <param name="pTaskBody">[in] Action to be executed.</param> /// <returns>A new <see cref="T:Microsoft.VisualStudio.Shell.Interop.IVsTask" /> instance that has the current task as its parent.</returns> public IVsTask ContinueWith(uint context, IVsTaskBody pTaskBody) => ContinueWithEx(context, 0, pTaskBody, null);
/// <inheritdoc /> public IVsTask CreateTask(uint context, IVsTaskBody pTaskBody) { return(this.CreateTaskEx(context, options: 0, pTaskBody: pTaskBody, pAsyncState: null)); }
/// <inheritdoc /> public IVsTask ContinueWhenAllCompleted(uint context, uint dwTasks, IVsTask[] pDependentTasks, IVsTaskBody pTaskBody) { return(this.ContinueWhenAllCompletedEx(context, dwTasks, pDependentTasks, options: 0, pTaskBody: pTaskBody, pAsyncState: null)); }
/// <inheritdoc /> public IVsTask ContinueWith(uint context, IVsTaskBody pTaskBody) { return(this.ContinueWithEx(context, 0, pTaskBody, pAsyncState: null)); }
/// <inheritdoc /> public IVsTask ContinueWhenAllCompletedEx(uint context, uint dwTasks, IVsTask[] pDependentTasks, uint options, IVsTaskBody pTaskBody, object?pAsyncState) { throw new NotImplementedException(); }
/// <summary> /// Initializes a new instance of the <see cref="MockVSTask"/> class. /// </summary> /// <param name="vsTaskSchedulerService2">The <see cref="SVsTaskSchedulerService"/>.</param> /// <param name="context">The scheduling option for this task.</param> /// <param name="taskBody">The body to execute.</param> /// <param name="asyncState">The async state object to store.</param> public MockVSTask(IVsTaskSchedulerService2 vsTaskSchedulerService2, uint context, IVsTaskBody taskBody, object?asyncState = null) { this.vsTaskSchedulerService2 = vsTaskSchedulerService2 ?? throw new ArgumentNullException(nameof(vsTaskSchedulerService2)); this.context = context; this.task = new Task <object>( () => { taskBody.DoWork(this, 0, Array.Empty <IVsTask>(), out object result); return(result); }, this.cancellationTokenSource.Token); this.asyncState = asyncState; }
/// <inheritdoc /> public IVsTask CreateTaskEx(uint context, uint options, IVsTaskBody pTaskBody, object?pAsyncState) { return(new MockVSTask(this, context, pTaskBody, pAsyncState)); }
public IVsTask ContinueWith(uint context, IVsTaskBody taskBody) { if (!this.IsCompleted) { this.Start(); } return this.ContinueWithEx(context, 0, taskBody, this.AsyncState); }