public int Choice(IEnumerable <Action> actions) { WIGStartInfo wigStartInfo = new WIGStartInfo { StartSuspended = true }; IWorkItemsGroup workItemsGroup = this.CreateWorkItemsGroup(2147483647, wigStartInfo); ManualResetEvent anActionCompleted = new ManualResetEvent(false); SmartThreadPool.ChoiceIndex choiceIndex = new SmartThreadPool.ChoiceIndex(); int num = 0; foreach (Action current in actions) { Action act = current; int value = num; workItemsGroup.QueueWorkItem(delegate { act(); Interlocked.CompareExchange(ref choiceIndex._index, value, -1); anActionCompleted.Set(); }); num++; } workItemsGroup.Start(); anActionCompleted.WaitOne(); return(choiceIndex._index); }
public WIGStartInfo(WIGStartInfo wigStartInfo) { this._useCallerCallContext = wigStartInfo.UseCallerCallContext; this._useCallerHttpContext = wigStartInfo.UseCallerHttpContext; this._disposeOfStateObjects = wigStartInfo.DisposeOfStateObjects; this._callToPostExecute = wigStartInfo.CallToPostExecute; this._postExecuteWorkItemCallback = wigStartInfo.PostExecuteWorkItemCallback; this._workItemPriority = wigStartInfo.WorkItemPriority; this._startSuspended = wigStartInfo.StartSuspended; this._fillStateWithArgs = wigStartInfo.FillStateWithArgs; }
public void Join(IEnumerable <Action> actions) { WIGStartInfo wigStartInfo = new WIGStartInfo { StartSuspended = true }; IWorkItemsGroup workItemsGroup = this.CreateWorkItemsGroup(2147483647, wigStartInfo); foreach (Action current in actions) { workItemsGroup.QueueWorkItem(current); } workItemsGroup.Start(); workItemsGroup.WaitForIdle(); }
public void Pipe <T>(T pipeState, IEnumerable <Action <T> > actions) { WIGStartInfo wigStartInfo = new WIGStartInfo { StartSuspended = true }; IWorkItemsGroup workItemsGroup = this.CreateWorkItemsGroup(2147483647, wigStartInfo); foreach (Action <T> current in actions) { Action <T> act = current; workItemsGroup.QueueWorkItem(delegate { act(pipeState); }); } workItemsGroup.Start(); workItemsGroup.WaitForIdle(); }
public IWorkItemsGroup CreateWorkItemsGroup(int concurrency, WIGStartInfo wigStartInfo) { return(new WorkItemsGroup(this, concurrency, wigStartInfo)); }