public WorkItemInfo(WorkItemInfo workItemInfo) { _useCallerCallContext = workItemInfo._useCallerCallContext; _useCallerHttpContext = workItemInfo._useCallerHttpContext; _disposeOfStateObjects = workItemInfo._disposeOfStateObjects; _callToPostExecute = workItemInfo._callToPostExecute; _postExecuteWorkItemCallback = workItemInfo._postExecuteWorkItemCallback; _workItemPriority = workItemInfo._workItemPriority; }
public WIGStartInfo() { _useCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext; _useCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext; _disposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects; _callToPostExecute = SmartThreadPool.DefaultCallToPostExecute; _postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback; _startSuspended = SmartThreadPool.DefaultStartSuspended; }
public WIGStartInfo(WIGStartInfo wigStartInfo) { _useCallerCallContext = wigStartInfo._useCallerCallContext; _useCallerHttpContext = wigStartInfo._useCallerHttpContext; _disposeOfStateObjects = wigStartInfo._disposeOfStateObjects; _callToPostExecute = wigStartInfo._callToPostExecute; _postExecuteWorkItemCallback = wigStartInfo._postExecuteWorkItemCallback; _startSuspended = wigStartInfo._startSuspended; }
public WorkItemInfo() { _useCallerCallContext = SmartThreadPool.DefaultUseCallerCallContext; _useCallerHttpContext = SmartThreadPool.DefaultUseCallerHttpContext; _disposeOfStateObjects = SmartThreadPool.DefaultDisposeOfStateObjects; _callToPostExecute = SmartThreadPool.DefaultCallToPostExecute; _postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback; _workItemPriority = SmartThreadPool.DefaultWorkItemPriority; }
// Token: 0x06001837 RID: 6199 // RVA: 0x00074E5C File Offset: 0x0007305C public WIGStartInfo(WIGStartInfo wigstartInfo_0) { this._useCallerCallContext = wigstartInfo_0.UseCallerCallContext; this._useCallerHttpContext = wigstartInfo_0.UseCallerHttpContext; this._disposeOfStateObjects = wigstartInfo_0.DisposeOfStateObjects; this._callToPostExecute = wigstartInfo_0.CallToPostExecute; this._postExecuteWorkItemCallback = wigstartInfo_0.PostExecuteWorkItemCallback; this._workItemPriority = wigstartInfo_0.WorkItemPriority; this._startSuspended = wigstartInfo_0.StartSuspended; this._fillStateWithArgs = wigstartInfo_0.FillStateWithArgs; }
// Token: 0x06001836 RID: 6198 // RVA: 0x00074E0C File Offset: 0x0007300C public WIGStartInfo() { this._fillStateWithArgs = false; this._workItemPriority = WorkItemPriority.Normal; this._startSuspended = false; this._postExecuteWorkItemCallback = SmartThreadPool.DefaultPostExecuteWorkItemCallback; this._callToPostExecute = CallToPostExecute.Always; this._disposeOfStateObjects = false; this._useCallerHttpContext = false; this._useCallerCallContext = false; }
public WIGStartInfo(WIGStartInfo wigStartInfo) { _useCallerCallContext = wigStartInfo.UseCallerCallContext; _useCallerHttpContext = wigStartInfo.UseCallerHttpContext; _disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; _callToPostExecute = wigStartInfo.CallToPostExecute; _postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback; _workItemPriority = wigStartInfo.WorkItemPriority; _startSuspended = wigStartInfo.StartSuspended; _fillStateWithArgs = wigStartInfo.FillStateWithArgs; }
/// <summary> /// Queue a work item /// </summary> /// <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> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="workItemPriority">The work item priority</param> /// <returns>Returns a work item result</returns> public IWorkItemResult QueueWorkItem( WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, WorkItemPriority workItemPriority) { PreQueueWorkItem(); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); Enqueue(workItem); return(workItem.GetWorkItemResult()); }
/// <summary> /// Queue a work item /// </summary> /// <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> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="workItemPriority">The work item priority</param> /// <returns>Returns a work item result</returns> public IWorkItemResult QueueWorkItem( WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, WorkItemPriority workItemPriority) { WorkItem workItem = WorkItemFactory.CreateWorkItem(this, _workItemsGroupStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); EnqueueToSTPNextWorkItem(workItem); return(workItem.GetWorkItemResult()); }
/// <summary> /// /// </summary> /// <param name="wigStartInfo"></param> public WIGStartInfo(WIGStartInfo wigStartInfo) { if (null == wigStartInfo) { throw new ArgumentNullException("wigStartInfo"); } _useCallerCallContext = wigStartInfo.UseCallerCallContext; _useCallerHttpContext = wigStartInfo.UseCallerHttpContext; _disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; _callToPostExecute = wigStartInfo.CallToPostExecute; _postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback; _workItemPriority = wigStartInfo.WorkItemPriority; _startSuspended = wigStartInfo.StartSuspended; _fillStateWithArgs = wigStartInfo.FillStateWithArgs; }
public void ChainedDelegatesPostExecute() { Assert.Throws <NotSupportedException> (() => { SmartThreadPool stp = new SmartThreadPool(); PostExecuteWorkItemCallback postExecuteWorkItemCallback = DoPostExecute; postExecuteWorkItemCallback += DoPostExecute; stp.QueueWorkItem(new WorkItemCallback(DoWork), null, postExecuteWorkItemCallback); stp.WaitForIdle(); stp.Shutdown(); }); }
public void ChainedDelegatesPostExecute() { Assert.Throws <NotSupportedException> (() => { SmartThreadPool smartThreadPool = new SmartThreadPool(); IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue); PostExecuteWorkItemCallback postExecuteWorkItemCallback = new PostExecuteWorkItemCallback(DoPostExecute); postExecuteWorkItemCallback += new PostExecuteWorkItemCallback(DoPostExecute); workItemsGroup.QueueWorkItem(new WorkItemCallback(DoWork), null, postExecuteWorkItemCallback); workItemsGroup.WaitForIdle(); smartThreadPool.Shutdown(); }); }
public void ChainedDelegatesPostExecute() { SmartThreadPool stp = new SmartThreadPool(); PostExecuteWorkItemCallback postExecuteWorkItemCallback = DoPostExecute; postExecuteWorkItemCallback += DoPostExecute; stp.QueueWorkItem( new WorkItemCallback(DoWork), null, postExecuteWorkItemCallback); stp.WaitForIdle(); stp.Shutdown(); }
/// <summary> /// Queues a user work item to the thread pool. /// </summary> /// <param name="callback"> /// A WaitCallback representing the delegate to invoke when the thread in the /// thread pool picks up the work item. /// </param> /// <param name="state"> /// The object that is passed to the delegate when serviced from the thread pool. /// </param> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <returns>Work item result</returns> public IWorkItemResult QueueWorkItem( WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback) { ValidateNotDisposed(); // Create a work item that contains the delegate and its state. WorkItem workItem = new WorkItem( callback, state, _useCallerContext, postExecuteWorkItemCallback, _callToPostExecute); Enqueue(workItem); return(workItem.GetWorkItemResult()); }
public void ChainedDelegatesPostExecute() { SmartThreadPool smartThreadPool = new SmartThreadPool(); IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue); PostExecuteWorkItemCallback postExecuteWorkItemCallback = new PostExecuteWorkItemCallback(DoPostExecute); postExecuteWorkItemCallback += new PostExecuteWorkItemCallback(DoPostExecute); workItemsGroup.QueueWorkItem( new WorkItemCallback(DoWork), null, postExecuteWorkItemCallback); workItemsGroup.WaitForIdle(); smartThreadPool.Shutdown(); }
/// <summary> /// Initialize the callback holding object. /// </summary> /// <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( WorkItemCallback callback, object state, bool useCallerContext, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute) { if (useCallerContext) { _callerContext = ChoCallerThreadContext.Capture(); } _postExecuteWorkItemCallback = postExecuteWorkItemCallback; _callToPostExecute = callToPostExecute; _callback = callback; _state = state; _workItemState = WorkItemState.InQueue; _workItemCompleted = null; _workItemCompletedRefCount = 0; _workItemResult = new WorkItemResult(this); }
/// <summary> /// Create a new work item /// </summary> /// <param name="workItemsGroup">The work items group</param> /// <param name="wigStartInfo">Work item group start 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> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <returns>Returns a work item</returns> public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback) { ValidateCallback(callback); ValidateCallback(postExecuteWorkItemCallback); WorkItemInfo workItemInfo = new WorkItemInfo { UseCallerCallContext = wigStartInfo.UseCallerCallContext, UseCallerHttpContext = wigStartInfo.UseCallerHttpContext, PostExecuteWorkItemCallback = postExecuteWorkItemCallback, CallToPostExecute = wigStartInfo.CallToPostExecute, DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects, WorkItemPriority = wigStartInfo.WorkItemPriority }; WorkItem workItem = new WorkItem( workItemsGroup, workItemInfo, callback, state); return(workItem); }
//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); }
private void TasksProducerThreadMain() { WorkItemCallback workItemCallback = new WorkItemCallback(this.SmartThreadMain); PostExecuteWorkItemCallback postExecuteWorkItemCallback = new PostExecuteWorkItemCallback(this.OneThreadDoneCallback); while (isProducerThreadRunning) { IWorkItemsGroup workItemsGroup = smartThreadPool; if (null == workItemsGroup) { return; } try { object data = this.curTaskGroup.OneTask_Produce(); if (data != null) { workItemCallback = new WorkItemCallback(this.SmartThreadMain); workItemsGroup.QueueWorkItem(workItemCallback, data, postExecuteWorkItemCallback, CallToPostExecute.Always); performance.tasksGenerated++; } else { GlobalVar.Instance.logger.Info("全部任务生产完毕."); isProducerThreadRunning = false; } } catch (ObjectDisposedException e) { e.GetHashCode(); break; } Thread.Sleep(10); } }
/// <summary> /// Queue a work item /// </summary> /// <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> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="workItemPriority">The work item priority</param> /// <returns>Returns a work item result</returns> public IWorkItemResult QueueWorkItem( WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, WorkItemPriority workItemPriority) { ValidateNotDisposed(); ValidateCallback(callback); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, _stpStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); Enqueue(workItem); return workItem.GetWorkItemResult(); }
/// <summary> /// Create a new work item /// </summary> /// <param name = "wigStartInfo">Work item group start 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> /// <param name = "postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <param name = "callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name = "workItemPriority">The work item priority</param> /// <returns>Returns a work item</returns> public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, WorkItemPriority workItemPriority) { ValidateCallback(callback); ValidateCallback(postExecuteWorkItemCallback); WorkItemInfo workItemInfo = new WorkItemInfo { UseCallerCallContext = wigStartInfo.UseCallerCallContext, UseCallerHttpContext = wigStartInfo.UseCallerHttpContext, PostExecuteWorkItemCallback = postExecuteWorkItemCallback, CallToPostExecute = callToPostExecute, WorkItemPriority = workItemPriority, DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects }; WorkItem workItem = new WorkItem( workItemsGroup, workItemInfo, callback, state); return workItem; }
//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); }
private void IrrWorkItemMaintainer() { while (true) { List<IrrWorkItem> items = null; lock (irrWorkItems) { if (irrWorkItems.Count > 0) { items = new List<IrrWorkItem>(irrWorkItems); } } if (items != null) { foreach (IrrWorkItem item in items) { if (item.retry <= asset_fetch_retry) { WorkItemCallback callback = new WorkItemCallback(item.callback); PostExecuteWorkItemCallback posthandler = new PostExecuteWorkItemCallback(PostIrrWorkItemHandler); requestingThreadPool.QueueWorkItem(callback, item, posthandler); item.retry++; } lock (irrWorkItems) { irrWorkItems.Remove(item); } } } System.Threading.Thread.Sleep(1000); } }
/// <summary> /// Create a new work item /// </summary> /// <param name="workItemsGroup"></param> /// <param name="wigStartInfo">Work item group start 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> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <returns>Returns a work item</returns> public static WorkItem CreateWorkItem( IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback) { ValidateCallback(callback); ValidateCallback(postExecuteWorkItemCallback); WorkItemInfo workItemInfo = new WorkItemInfo(); workItemInfo.UseCallerCallContext = wigStartInfo.UseCallerCallContext; workItemInfo.UseCallerHttpContext = wigStartInfo.UseCallerHttpContext; workItemInfo.PostExecuteWorkItemCallback = postExecuteWorkItemCallback; workItemInfo.CallToPostExecute = wigStartInfo.CallToPostExecute; workItemInfo.DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; WorkItem workItem = new WorkItem( workItemsGroup, workItemInfo, callback, state); return workItem; }
/// <summary> /// Queue a work item /// </summary> /// <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> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="workItemPriority">The work item priority</param> /// <returns>Returns a work item result</returns> public IWorkItemResult QueueWorkItem( WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, WorkItemPriority workItemPriority) { WorkItem workItem = WorkItemFactory.CreateWorkItem(this, _workItemsGroupStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); EnqueueToSTPNextWorkItem(workItem); return workItem.GetWorkItemResult(); }
/// <summary> /// Queue a work item /// </summary> /// <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> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <returns>Returns a work item result</returns> public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback) { WorkItem workItem = WorkItemFactory.CreateWorkItem(this, this._workItemsGroupStartInfo, callback, state, postExecuteWorkItemCallback); this.EnqueueToSTPNextWorkItem(workItem); return(workItem.GetWorkItemResult()); }
/// <summary> /// Create a new work item /// </summary> /// <param name="workItemsGroup"></param> /// <param name="wigStartInfo">Work item group start 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> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="workItemPriority">The work item priority</param> /// <returns>Returns a work item</returns> public static WorkItem CreateWorkItem(IWorkItemsGroup workItemsGroup, WIGStartInfo wigStartInfo, WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, WorkItemPriority workItemPriority) { ValidateCallback(callback); ValidateCallback(postExecuteWorkItemCallback); return(new WorkItem(workItemsGroup, new WorkItemInfo { UseCallerCallContext = wigStartInfo.UseCallerCallContext, UseCallerHttpContext = wigStartInfo.UseCallerHttpContext, PostExecuteWorkItemCallback = postExecuteWorkItemCallback, CallToPostExecute = callToPostExecute, WorkItemPriority = workItemPriority, DisposeOfStateObjects = wigStartInfo.DisposeOfStateObjects }, callback, state)); }
/// <summary> /// Sends the email to recipients. /// </summary> /// <param name="site">The site.</param> /// <param name="documents">The updated documents.</param> public void SendEmailToRecipients(string site, int batchId) { try { List <Subscription> subscribers = SubscriptionService.GetCurrentSubscribers(site); if (null == subscribers || subscribers.Count == 0) { log.Info("No Subscribers - email will not be sent"); return; } string emailTemplateURL = null; string emailSubject = null; using (NotificationTablesDataContext dataContext = new NotificationTablesDataContext()) { SiteConfiguration siteConfiguration = dataContext.SiteConfigurations.FirstOrDefault(siteName => siteName.site == site); emailTemplateURL = siteConfiguration.emailTemplateURL; emailSubject = siteConfiguration.siteName + " " + (ConfigurationManager.AppSettings["Email.Subject"] as String); } string messageBody = GetEmailBody(emailTemplateURL + "?batchId=" + batchId); SmartThreadPool smartThreadPool = new SmartThreadPool(); IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(maxThreads); foreach (Subscription subscription in subscribers) { Email email = new Email { to = subscription.email, from = FromAddress, body = messageBody, subject = emailSubject }; PostExecuteWorkItemCallback afterEmailSend = delegate { SaveSentMailInformation(site, batchId, email); }; WorkItemInfo workItem = new WorkItemInfo(); workItem.PostExecuteWorkItemCallback = afterEmailSend; workItemsGroup.QueueWorkItem(workItem, SendMail, email); } workItemsGroup.WaitForIdle(); smartThreadPool.Shutdown(); using (NotificationTablesDataContext dataContext = new NotificationTablesDataContext()) { Batch batch = dataContext.Batches.FirstOrDefault(b => b.site == site && b.batchId == batchId); batch.finishDate = DateTime.Now; batch.status = "Successful"; dataContext.SubmitChanges(); } } catch (Exception e) { log.Error("Unable to Send Email", e); using (NotificationTablesDataContext dataContext = new NotificationTablesDataContext()) { Batch batch = dataContext.Batches.FirstOrDefault(b => b.site == site && b.batchId == batchId); batch.status = "Unsuccessful"; dataContext.SubmitChanges(); } throw e; } }
public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute) { this.PreQueueWorkItem(); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, this.WIGStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute); this.Enqueue(workItem); return(workItem.GetWorkItemResult()); }
/// <summary> /// Queue a work item /// </summary> /// <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> /// <param name="postExecuteWorkItemCallback"> /// A delegate to call after the callback completion /// </param> /// <param name="callToPostExecute">Indicates on which cases to call to the post execute callback</param> /// <param name="workItemPriority">The work item priority</param> /// <returns>Returns a work item result</returns> public IWorkItemResult QueueWorkItem(WorkItemCallback callback, object state, PostExecuteWorkItemCallback postExecuteWorkItemCallback, CallToPostExecute callToPostExecute, WorkItemPriority workItemPriority) { this.ValidateNotDisposed(); this.ValidateCallback(callback); WorkItem workItem = WorkItemFactory.CreateWorkItem(this, this._stpStartInfo, callback, state, postExecuteWorkItemCallback, callToPostExecute, workItemPriority); this.Enqueue(workItem); return(workItem.GetWorkItemResult()); }