本文整理汇总了C#中Amib.Threading.SmartThreadPool.CreateWorkItemsGroup方法的典型用法代码示例。如果您正苦于以下问题:C# SmartThreadPool.CreateWorkItemsGroup方法的具体用法?C# SmartThreadPool.CreateWorkItemsGroup怎么用?C# SmartThreadPool.CreateWorkItemsGroup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amib.Threading.SmartThreadPool
的用法示例。
在下文中一共展示了SmartThreadPool.CreateWorkItemsGroup方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TwoWIGsStartSuspended
public void TwoWIGsStartSuspended()
{
SmartThreadPool stp = new SmartThreadPool();
WIGStartInfo wigStartInfo = new WIGStartInfo();
wigStartInfo.StartSuspended = true;
IWorkItemsGroup wig1 = stp.CreateWorkItemsGroup(10, wigStartInfo);
IWorkItemsGroup wig2 = stp.CreateWorkItemsGroup(10, wigStartInfo);
wig1.QueueWorkItem(new WorkItemCallback(this.DoWork));
wig2.QueueWorkItem(new WorkItemCallback(this.DoWork));
Assert.IsFalse(wig1.WaitForIdle(200));
Assert.IsFalse(wig2.WaitForIdle(200));
wig1.Start();
Assert.IsTrue(wig1.WaitForIdle(200));
Assert.IsFalse(wig2.WaitForIdle(200));
wig2.Start();
Assert.IsTrue(wig1.WaitForIdle(0));
Assert.IsTrue(wig2.WaitForIdle(200));
}
示例2: WaitForIdleOnSTPThreadForAnotherWorkItemsGroup
public void WaitForIdleOnSTPThreadForAnotherWorkItemsGroup()
{
SmartThreadPool smartThreadPool = new SmartThreadPool(10*1000, 25, 0);
IWorkItemsGroup workItemsGroup1 = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);
IWorkItemsGroup workItemsGroup2 = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);
workItemsGroup1.QueueWorkItem(
new WorkItemCallback(this.DoSomeWork),
1000);
workItemsGroup1.QueueWorkItem(
new WorkItemCallback(this.DoSomeWork),
1000);
IWorkItemResult wir = workItemsGroup2.QueueWorkItem(
new WorkItemCallback(this.DoWaitForIdle),
workItemsGroup1);
Exception e;
wir.GetResult(out e);
smartThreadPool.Shutdown();
Assert.IsNull(e);
}
示例3: TestWIGConcurrencyChange2WIGs
public void TestWIGConcurrencyChange2WIGs()
{
SmartThreadPool smartThreadPool = new SmartThreadPool(10 * 1000, 2, 0);
Assert.IsTrue(0 == smartThreadPool.WaitingCallbacks);
PauseSTP(smartThreadPool);
PauseSTP(smartThreadPool);
Thread.Sleep(100);
Assert.IsTrue(0 == smartThreadPool.WaitingCallbacks);
IWorkItemsGroup wig1 = smartThreadPool.CreateWorkItemsGroup(1);
IWorkItemsGroup wig2 = smartThreadPool.CreateWorkItemsGroup(1);
wig1.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
Assert.IsTrue(1 == smartThreadPool.WaitingCallbacks);
wig2.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
Assert.IsTrue(2 == smartThreadPool.WaitingCallbacks);
wig1.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
Assert.IsTrue(2 == smartThreadPool.WaitingCallbacks);
wig2.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
Assert.IsTrue(2 == smartThreadPool.WaitingCallbacks);
wig1.Concurrency = 2;
Thread.Sleep(100);
Assert.IsTrue(3 == smartThreadPool.WaitingCallbacks);
wig2.Concurrency = 2;
Thread.Sleep(100);
Assert.IsTrue(4 == smartThreadPool.WaitingCallbacks);
ResumeSTP(smartThreadPool);
Thread.Sleep(100);
Assert.IsTrue(0 == smartThreadPool.WaitingCallbacks);
PauseSTP(smartThreadPool);
PauseSTP(smartThreadPool);
Thread.Sleep(100);
wig1.Concurrency = 1;
wig1.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
Assert.IsTrue(1 == smartThreadPool.WaitingCallbacks);
wig2.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
Assert.IsTrue(2 == smartThreadPool.WaitingCallbacks);
ResumeSTP(smartThreadPool);
Thread.Sleep(100);
Assert.IsTrue(0 == smartThreadPool.WaitingCallbacks);
smartThreadPool.Shutdown();
}
示例4: ExceptionThrowing
public void ExceptionThrowing()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);
DivArgs divArgs = new DivArgs();
divArgs.x = 10;
divArgs.y = 0;
IWorkItemResult wir =
workItemsGroup.QueueWorkItem(new WorkItemCallback(this.DoDiv), divArgs);
try
{
wir.GetResult();
}
catch(WorkItemResultException wire)
{
Assert.IsTrue(wire.InnerException is DivideByZeroException);
return;
}
catch(Exception e)
{
e.GetHashCode();
Assert.Fail();
}
Assert.Fail();
}
示例5: ExceptionReturning
public void ExceptionReturning()
{
bool success = true;
SmartThreadPool smartThreadPool = new SmartThreadPool();
IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);
DivArgs divArgs = new DivArgs();
divArgs.x = 10;
divArgs.y = 0;
IWorkItemResult wir =
workItemsGroup.QueueWorkItem(new WorkItemCallback(this.DoDiv), divArgs);
Exception e = null;
try
{
wir.GetResult(out e);
}
catch (Exception ex)
{
ex.GetHashCode();
success = false;
}
Assert.IsTrue(success);
Assert.IsTrue(e is DivideByZeroException);
}
示例6: DisposeCallerState
public void DisposeCallerState()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
WIGStartInfo wigStartInfo = new WIGStartInfo();
wigStartInfo.DisposeOfStateObjects = true;
IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue, wigStartInfo);
CallerState nonDisposableCallerState = new NonDisposableCallerState();
CallerState disposableCallerState = new DisposableCallerState();
IWorkItemResult wir1 =
workItemsGroup.QueueWorkItem(
new WorkItemCallback(this.DoSomeWork),
nonDisposableCallerState);
IWorkItemResult wir2 =
workItemsGroup.QueueWorkItem(
new WorkItemCallback(this.DoSomeWork),
disposableCallerState);
wir1.GetResult();
Assert.AreEqual(1, nonDisposableCallerState.Value);
wir2.GetResult();
// Wait a little bit for the working thread to call dispose on the
// work item's state.
workItemsGroup.WaitForIdle();
Assert.AreEqual(2, disposableCallerState.Value);
smartThreadPool.Shutdown();
}
示例7: STPAndWIGStartSuspended
public void STPAndWIGStartSuspended()
{
STPStartInfo stpStartInfo = new STPStartInfo();
stpStartInfo.StartSuspended = true;
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
WIGStartInfo wigStartInfo = new WIGStartInfo();
wigStartInfo.StartSuspended = true;
IWorkItemsGroup wig = stp.CreateWorkItemsGroup(10, wigStartInfo);
wig.QueueWorkItem(new WorkItemCallback(this.DoWork));
Assert.IsFalse(wig.WaitForIdle(200));
wig.Start();
Assert.IsFalse(wig.WaitForIdle(200));
stp.Start();
Assert.IsTrue(wig.WaitForIdle(5000), "WIG is not idle");
Assert.IsTrue(stp.WaitForIdle(5000), "STP is not idle");
}
示例8: WaitAny
public void WaitAny()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);
bool success = false;
IWorkItemResult [] wirs = new IWorkItemResult[5];
for(int i = 0; i < wirs.Length; ++i)
{
wirs[i] =
workItemsGroup.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
}
int index = SmartThreadPool.WaitAny(wirs);
if (wirs[index].IsCompleted)
{
int result = (int)wirs[index].GetResult();
if (1 == result)
{
success = true;
}
}
smartThreadPool.Shutdown();
Assert.IsTrue(success);
}
示例9: WorkItemWaitCanceling
public void WorkItemWaitCanceling()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);
ManualResetEvent cancelWaitHandle = new ManualResetEvent(false);
bool success = false;
// Queue a work item that will occupy the thread in the pool
IWorkItemResult wir1 =
workItemsGroup.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
// Queue another work item that will wait for the first to complete
IWorkItemResult wir2 =
workItemsGroup.QueueWorkItem(new WorkItemCallback(this.SignalCancel), cancelWaitHandle);
try
{
wir1.GetResult(System.Threading.Timeout.Infinite, true, cancelWaitHandle);
}
catch (WorkItemTimeoutException)
{
success = true;
}
smartThreadPool.Shutdown();
Assert.IsTrue(success);
}
示例10: TestWIGConcurrencyChange
public void TestWIGConcurrencyChange()
{
SmartThreadPool smartThreadPool = new SmartThreadPool(10 * 1000, 25, 0);
IWorkItemsGroup wig = smartThreadPool.CreateWorkItemsGroup(smartThreadPool.MaxThreads);
bool success = false;
for (int i = 0; i < 100; ++i)
{
wig.QueueWorkItem(new WorkItemCallback(this.DoSomeLongWork), null);
}
wig.Concurrency = 1;
success = WaitForWIGThreadsInUse(wig, 1, 1 * 1000);
Assert.IsTrue(success);
wig.Concurrency = 5;
success = WaitForWIGThreadsInUse(wig, 5, 2 * 1000);
Assert.IsTrue(success);
wig.Concurrency = 25;
success = WaitForWIGThreadsInUse(wig, 25, 4 * 1000);
Assert.IsTrue(success);
wig.Concurrency = 10;
success = WaitForWIGThreadsInUse(wig, 10, 10 * 1000);
Assert.IsTrue(success);
smartThreadPool.Shutdown();
}
示例11: Init
public void Init()
{
_stp = new SmartThreadPool();
WIGStartInfo wigStartInfo = new WIGStartInfo();
wigStartInfo.FillStateWithArgs = true;
_wig = _stp.CreateWorkItemsGroup(10, wigStartInfo);
}
示例12: HashCalculator
public HashCalculator(IHashAlgorithm method, SmartThreadPool pool)
{
_method = method;
_pool = pool;
if(_hashGroup == null)
{
_hashGroup = _pool.CreateWorkItemsGroup(1);
}
}
示例13: GoodCallback
public void GoodCallback()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);
workItemsGroup.QueueWorkItem(new WorkItemCallback(DoWork));
workItemsGroup.WaitForIdle();
smartThreadPool.Shutdown();
}
示例14: ChainedDelegatesCallback
public void ChainedDelegatesCallback()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
IWorkItemsGroup workItemsGroup = smartThreadPool.CreateWorkItemsGroup(int.MaxValue);
WorkItemCallback workItemCallback = new WorkItemCallback(DoWork);
workItemCallback += new WorkItemCallback(DoWork);
workItemsGroup.QueueWorkItem(workItemCallback);
workItemsGroup.WaitForIdle();
smartThreadPool.Shutdown();
}
示例15: Cancel1WIGof2WorkItems
public void Cancel1WIGof2WorkItems()
{
int counter1 = 0;
int counter2 = 0;
SmartThreadPool stp = new SmartThreadPool();
IWorkItemsGroup wig1 = stp.CreateWorkItemsGroup(3);
IWorkItemsGroup wig2 = stp.CreateWorkItemsGroup(3);
for (int i = 0; i < 3; i++)
{
wig1.QueueWorkItem(
state => { Interlocked.Increment(ref counter1); Thread.Sleep(500); Interlocked.Increment(ref counter1); return null; }
);
}
for (int i = 0; i < 3; i++)
{
wig2.QueueWorkItem(
state => { Thread.Sleep(500); Interlocked.Increment(ref counter2); return null; }
);
}
while (counter1 < 3)
{
Thread.Sleep(1);
}
wig1.Cancel(true);
stp.WaitForIdle();
Assert.AreEqual(3, counter1, "Cancelled WIG1");
Assert.AreEqual(3, counter2, "Normal WIG2");
stp.Shutdown();
}