//IWorkItemResult QueueWorkItem(WorkItemCallback callback); public static void TestQueueWorkItemCall(IWorkItemsGroup wig) { WorkItemInfo wii = new WorkItemInfo(); WorkItemInfoComparer wiic = new WorkItemInfoComparer(wii); IWorkItemResult wir = wig.QueueWorkItem(wiic.CompareWorkItemInfo); bool success = (bool)wir.Result; Assert.IsTrue(success); }
//IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state); public static void TestQueueWorkItemCallStat(IWorkItemsGroup wig) { object state = new object(); WorkItemInfo wii = new WorkItemInfo(); WorkItemInfoComparer wiic = new WorkItemInfoComparer(wii, state); IWorkItemResult wir = wig.QueueWorkItem((WorkItemCallback) wiic.CompareWorkItemInfo, state); bool success = (bool)wir.Result; Assert.IsTrue(success); }
//IWorkItemResult QueueWorkItem(WorkItemCallback callback, WorkItemPriority workItemPriority); public static void TestQueueWorkItemCallPrio(IWorkItemsGroup wig) { WorkItemInfo wii = new WorkItemInfo(); wii.WorkItemPriority = WorkItemPriority.AboveNormal; WorkItemInfoComparer wiic = new WorkItemInfoComparer(wii); IWorkItemResult wir = wig.QueueWorkItem((WorkItemCallback)wiic.CompareWorkItemInfo, WorkItemPriority.AboveNormal); bool success = (bool)wir.Result; Assert.IsTrue(success); }
//IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, WorkItemPriority workItemPriority); public static void TestQueueWorkItemCallStatPrio(IWorkItemsGroup wig) { object state = new object(); WorkItemInfo wii = new WorkItemInfo(); wii.WorkItemPriority = WorkItemPriority.AboveNormal; WorkItemInfoComparer wiic = new WorkItemInfoComparer(wii, state); IWorkItemResult wir = wig.QueueWorkItem(wiic.CompareWorkItemInfo, state, WorkItemPriority.AboveNormal); bool success = (bool)wir.Result; Assert.IsTrue(success); }
//IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback); public static void TestQueueWorkItemCallStatPost(IWorkItemsGroup wig) { bool postExecuteCalled = false; object state = new object(); PostExecuteWorkItemCallback postExecuteWorkItemCallback = delegate(IWorkItemResult w) { postExecuteCalled = true; }; WorkItemInfo wii = new WorkItemInfo(); wii.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; WorkItemInfoComparer wiic = new WorkItemInfoComparer(wii, state); IWorkItemResult wir = wig.QueueWorkItem( wiic.CompareWorkItemInfo, state, postExecuteWorkItemCallback); // We must wait for idle to let the post execute run wig.WaitForIdle(); bool success = (bool)wir.Result; Assert.IsTrue(success); Assert.IsTrue(postExecuteCalled); }
/// <summary> /// Initialize the callback holding object. /// </summary> /// <param name="workItemsGroup">The workItemGroup of the workitem</param> /// <param name="workItemInfo">The WorkItemInfo of te workitem</param> /// <param name="callback">Callback delegate for the callback.</param> /// <param name="state">State with which to call the callback delegate.</param> /// /// We assume that the WorkItem object is created within the thread /// that meant to run the callback public WorkItem( IWorkItemsGroup workItemsGroup, WorkItemInfo workItemInfo, WorkItemCallback callback, object state) { _workItemsGroup = workItemsGroup; _workItemInfo = workItemInfo; #if !(_WINDOWS_CE) && !(_SILVERLIGHT) && !(WINDOWS_PHONE) if (_workItemInfo.UseCallerCallContext || _workItemInfo.UseCallerHttpContext) { _callerContext = CallerThreadContext.Capture(_workItemInfo.UseCallerCallContext, _workItemInfo.UseCallerHttpContext); } #endif _callback = callback; _state = state; _workItemResult = new WorkItemResult(this); Initialize(); }
/// <summary> /// Queue a work item /// </summary> /// <param name="workItemInfo">Work item information</param> /// <param name="callback">A callback to execute</param> /// <param name="state"> /// The context object of the work item. Used for passing arguments to the work item. /// </param> /// <returns>Returns a work item result</returns> public IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state) { ValidateNotDisposed(); ValidateCallback(callback); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, _stpStartInfo, workItemInfo, callback, state); Enqueue(workItem); return workItem.GetWorkItemResult(); }
private bool CompareWorkItemInfo(WorkItemInfo wii1, WorkItemInfo wii2) { bool equal = true; equal = equal && (wii1.CallToPostExecute == wii2.CallToPostExecute); equal = equal && (wii1.DisposeOfStateObjects == wii2.DisposeOfStateObjects); equal = equal && (wii1.PostExecuteWorkItemCallback == wii2.PostExecuteWorkItemCallback); equal = equal && (wii1.UseCallerCallContext == wii2.UseCallerCallContext); equal = equal && (wii1.UseCallerHttpContext == wii2.UseCallerHttpContext); equal = equal && (wii1.WorkItemPriority == wii2.WorkItemPriority); return equal; }
public WorkItemInfoComparer(WorkItemInfo workItemInfo, object state) { _neededWorkItemInfo = workItemInfo; _state = state; }
public WorkItemInfoComparer(WorkItemInfo workItemInfo) { _neededWorkItemInfo = workItemInfo; _state = null; }
//IWorkItemResult QueueWorkItem(WorkItemInfo workItemInfo, WorkItemCallback callback, object state); public static void TestQueueWorkItemInfoCallStat(IWorkItemsGroup wig) { object state = new object(); WorkItemInfo wii = new WorkItemInfo(); wii.CallToPostExecute = CallToPostExecute.Never; wii.DisposeOfStateObjects = true; wii.PostExecuteWorkItemCallback = delegate(IWorkItemResult w) { }; wii.UseCallerCallContext = true; wii.UseCallerHttpContext = true; wii.WorkItemPriority = WorkItemPriority.Highest; WorkItemInfoComparer wiic = new WorkItemInfoComparer(wii, state); IWorkItemResult wir = wig.QueueWorkItem(wii, wiic.CompareWorkItemInfo, state); // We must wait for idle to let the post execute run wig.WaitForIdle(); bool success = (bool)wir.Result; Assert.IsTrue(success); }
//IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, WorkItemPriority workItemPriority); public static void TestQueueWorkItemCallStatPostPflgPrio(IWorkItemsGroup wig) { bool postExecuteCalled; CallToPostExecute callToPostExecute; object state = new object(); PostExecuteWorkItemCallback postExecuteWorkItemCallback = delegate(IWorkItemResult w) { postExecuteCalled = true; }; WorkItemInfo wii = new WorkItemInfo(); wii.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; WorkItemInfoComparer wiic = new WorkItemInfoComparer(wii, state); WorkItemPriority workItemPriority; IWorkItemResult wir; bool success; ///////////////////////////////////////////////////////////////////////////// callToPostExecute = CallToPostExecute.Always; workItemPriority = WorkItemPriority.Lowest; // Check without cancel postExecuteCalled = false; wiic.SleepTime = 0; wii.CallToPostExecute = callToPostExecute; wii.WorkItemPriority = workItemPriority; wir = wig.QueueWorkItem( wiic.CompareWorkItemInfo, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); // We must wait for idle to let the post execute run wig.WaitForIdle(); success = (bool)wir.Result; Assert.IsTrue(success); Assert.IsTrue(postExecuteCalled); // Check with cancel success = false; postExecuteCalled = false; wiic.SleepTime = 100; wir = wig.QueueWorkItem( wiic.CompareWorkItemInfo, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); wir.Cancel(); // We must wait for idle to let the post execute run wig.WaitForIdle(); Assert.IsTrue(postExecuteCalled); try { wir.GetResult(); } catch (WorkItemCancelException ce) { success = true; } Assert.IsTrue(success); ///////////////////////////////////////////////////////////////////////////// callToPostExecute = CallToPostExecute.Never; workItemPriority = WorkItemPriority.Highest; postExecuteCalled = false; wiic.SleepTime = 0; wii.CallToPostExecute = callToPostExecute; wii.WorkItemPriority = workItemPriority; wir = wig.QueueWorkItem( wiic.CompareWorkItemInfo, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); // We must wait for idle to let the post execute run wig.WaitForIdle(); success = (bool)wir.Result; Assert.IsTrue(success); Assert.IsFalse(postExecuteCalled); // Check with cancel success = false; postExecuteCalled = false; wiic.SleepTime = 100; wir = wig.QueueWorkItem( wiic.CompareWorkItemInfo, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); wir.Cancel(); // We must wait for idle to let the post execute run wig.WaitForIdle(); Assert.IsFalse(postExecuteCalled); try { wir.GetResult(); } catch (WorkItemCancelException ce) { success = true; } Assert.IsTrue(success); ///////////////////////////////////////////////////////////////////////////// callToPostExecute = CallToPostExecute.WhenWorkItemNotCanceled; workItemPriority = WorkItemPriority.AboveNormal; postExecuteCalled = false; wiic.SleepTime = 0; wii.CallToPostExecute = callToPostExecute; wii.WorkItemPriority = workItemPriority; wir = wig.QueueWorkItem( wiic.CompareWorkItemInfo, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); // We must wait for idle to let the post execute run wig.WaitForIdle(); success = (bool)wir.Result; Assert.IsTrue(success); Assert.IsTrue(postExecuteCalled); // Check with cancel success = false; postExecuteCalled = false; wiic.SleepTime = 100; wir = wig.QueueWorkItem( wiic.CompareWorkItemInfo, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); wir.Cancel(); // We must wait for idle to let the post execute run wig.WaitForIdle(); Assert.IsFalse(postExecuteCalled); try { wir.GetResult(); } catch (WorkItemCancelException ce) { success = true; } Assert.IsTrue(success); ///////////////////////////////////////////////////////////////////////////// callToPostExecute = CallToPostExecute.WhenWorkItemCanceled; workItemPriority = WorkItemPriority.BelowNormal; postExecuteCalled = false; wiic.SleepTime = 0; wii.CallToPostExecute = callToPostExecute; wii.WorkItemPriority = workItemPriority; wir = wig.QueueWorkItem( wiic.CompareWorkItemInfo, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); // We must wait for idle to let the post execute run wig.WaitForIdle(); success = (bool)wir.Result; Assert.IsTrue(success); Assert.IsFalse(postExecuteCalled); // Check with cancel success = false; postExecuteCalled = false; wiic.SleepTime = 100; wir = wig.QueueWorkItem( wiic.CompareWorkItemInfo, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); wir.Cancel(); // We must wait for idle to let the post execute run wig.WaitForIdle(); Assert.IsTrue(postExecuteCalled); try { wir.GetResult(); } catch (WorkItemCancelException ce) { success = true; } Assert.IsTrue(success); }