本文整理汇总了C#中Amib.Threading.SmartThreadPool类的典型用法代码示例。如果您正苦于以下问题:C# SmartThreadPool类的具体用法?C# SmartThreadPool怎么用?C# SmartThreadPool使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SmartThreadPool类属于Amib.Threading命名空间,在下文中一共展示了SmartThreadPool类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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);
}
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:25,代码来源:TestWIGWaitForIdle.cs
示例2: WaitAllT
public void WaitAllT()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
bool success = true;
IWorkItemResult<int>[] wirs = new IWorkItemResult<int>[5];
for (int i = 0; i < wirs.Length; ++i)
{
wirs[i] = smartThreadPool.QueueWorkItem(new Func<int, int, int>(System.Math.Min), i, i + 1);
}
SmartThreadPool.WaitAll(wirs);
for (int i = 0; i < wirs.Length; ++i)
{
if (!wirs[i].IsCompleted)
{
success = false;
break;
}
int result = wirs[i].GetResult();
if (i != result)
{
success = false;
break;
}
}
smartThreadPool.Shutdown();
Assert.IsTrue(success);
}
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:35,代码来源:TestMultipleWorkItems.cs
示例3: CancelCanceledWorkItem
public void CancelCanceledWorkItem()
{
STPStartInfo stpStartInfo = new STPStartInfo();
stpStartInfo.StartSuspended = true;
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
IWorkItemResult wir = stp.QueueWorkItem(state => null);
int counter = 0;
wir.Cancel();
try
{
wir.GetResult();
}
catch (WorkItemCancelException ce)
{
ce.GetHashCode();
++counter;
}
Assert.AreEqual(counter, 1);
wir.Cancel();
try
{
wir.GetResult();
}
finally
{
stp.Shutdown();
}
}
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:35,代码来源:TestCancel.cs
示例4: test
public void test()
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
Curl.GlobalInit((int)CURLinitFlag.CURL_GLOBAL_ALL);
GlobalVar.isCrawling = true;
//string conn = string.Format(@"Data Source="+System.Environment.CurrentDirectory+"\\data\\{0}", GlobalVar.filename);
sqlitehelper con = new sqlitehelper(System.Environment.CurrentDirectory + @"\data\" + GlobalVar.filename);
string sql = "select keyword from Content where flag==0";
DataTable dt = new DataTable();
dt = con.GetDataTable(sql);
IWorkItemResult[] wir = new IWorkItemResult[dt.Rows.Count];
MessageBox.Show(dt.Rows.Count.ToString());
for (int i = 0; i < dt.Rows.Count; i++)
{
//MessageBox.Show(dt.Rows[i]["keyword"].ToString());
OneWorker one = new OneWorker(dt.Rows[i]["keyword"].ToString());
ThreadPool.QueueUserWorkItem(one.work, i);
}
bool success = SmartThreadPool.WaitAll(
wir);
if (success)
{
GlobalVar.isCrawling = false;
}
smartThreadPool.Shutdown();
}
开发者ID:shellleyma,项目名称:sescraper,代码行数:31,代码来源:ThreadControl.cs
示例5: 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);
}
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:30,代码来源:TestWIGMultipleWorkItems.cs
示例6: TestConcurrencyChange
public void TestConcurrencyChange()
{
SmartThreadPool smartThreadPool = new SmartThreadPool(10 * 1000, 1, 0);
bool success = false;
for (int i = 0; i < 100; ++i)
{
smartThreadPool.QueueWorkItem(
new WorkItemCallback(this.DoSomeWork),
null);
}
smartThreadPool.Concurrency = 1;
success = WaitForMaxThreadsValue(smartThreadPool, 1, 1 * 1000);
Assert.IsTrue(success);
smartThreadPool.Concurrency = 5;
success = WaitForMaxThreadsValue(smartThreadPool, 5, 2 * 1000);
Assert.IsTrue(success);
smartThreadPool.Concurrency = 25;
success = WaitForMaxThreadsValue(smartThreadPool, 25, 4 * 1000);
Assert.IsTrue(success);
smartThreadPool.Concurrency = 10;
success = WaitForMaxThreadsValue(smartThreadPool, 10, 10 * 1000);
Assert.IsTrue(success);
smartThreadPool.Shutdown();
}
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:31,代码来源:TestConcurrencyChanges.cs
示例7: WorkItemWaitCanceling
public void WorkItemWaitCanceling()
{
Assert.Throws<WorkItemTimeoutException>(() =>
{
SmartThreadPool smartThreadPool = new SmartThreadPool();
ManualResetEvent cancelWaitHandle = new ManualResetEvent(false);
// Queue a work item that will occupy the thread in the pool
IWorkItemResult wir1 =
smartThreadPool.QueueWorkItem(new WorkItemCallback(this.DoSomeWork), null);
// Queue another work item that will wait for the first to complete
IWorkItemResult wir2 =
smartThreadPool.QueueWorkItem(new WorkItemCallback(this.SignalCancel), cancelWaitHandle);
try
{
wir1.GetResult(System.Threading.Timeout.Infinite, true, cancelWaitHandle);
}
finally
{
smartThreadPool.Shutdown();
}
});
}
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:26,代码来源:TestGetResult.cs
示例8: getImagesAsync
public static void getImagesAsync(List<FilmData> tempFilmList)
{
if (isNetworkAvailable())
{
SmartThreadPool smartThreadPool = new SmartThreadPool(
15 * 1000, // Idle timeout in milliseconds
25, // Threads upper limit
1); // Threads lower limit
var bw = new System.ComponentModel.BackgroundWorker();
bw.DoWork += (s, args) =>
{
foreach (FilmData item in tempFilmList)
{
if (IsolatedStorageHelper.isFileAlreadySaved(item.imageUrl))
ImageHelper.addDownloadedItemsToFilmCollection(item.imageUrl);
else
smartThreadPool.QueueWorkItem(() => getImageFromUrl(item.imageUrl));
}
smartThreadPool.WaitForIdle(); // Wait for the completion of all work items
};
bw.RunWorkerAsync();
}
}
开发者ID:asdForever,项目名称:TouchInstinctTestApp,代码行数:25,代码来源:Networking.cs
示例9: 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");
}
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:25,代码来源:TestStartSuspended.cs
示例10: 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);
}
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:30,代码来源:TestWIGGetResult.cs
示例11: btnStart_Click
private void btnStart_Click(object sender, RoutedEventArgs e)
{
if (_running)
{
_wakeupEvent.Set();
_stp.Cancel();
_stp.Shutdown(false, 5000);
_stp = null;
btnStart.Content = "Start";
//txtIdleTimeout.Enabled = true;
_running = false;
}
else
{
usageHistoryControl1.Reset();
usageControl1.Value1 = 0;
usageControl1.Value2 = 0;
_wakeupEvent.Set();
_running = true;
btnStart.Content = "Stop";
//txtIdleTimeout.Enabled = false;
STPStartInfo stpStartInfo = new STPStartInfo()
{
MinWorkerThreads = Convert.ToInt32(txtMinThreads.Text),
MaxWorkerThreads = Convert.ToInt32(txtMaxThreads.Text),
IdleTimeout = Convert.ToInt32(txtIdleTimeout.Text) * 1000,
EnableLocalPerformanceCounters = true,
};
_stp = new SmartThreadPool(stpStartInfo);
}
}
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:32,代码来源:MainPage.xaml.cs
示例12: 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));
}
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:26,代码来源:TestStartSuspended.cs
示例13: calculateLabel
private static int calculateLabel(Individual[] weights)
{
Individual[] reversedWeights = { weights[1], weights[0] };
weights[1].ResetScores();
weights[0].ResetScores();
SmartThreadPool smtp = new SmartThreadPool();
for (int index = 0; index < numberOfGames; index++)
{
if (index % 2 == 1)
{
smtp.QueueWorkItem(new WorkItemCallback(threadProc), weights);
}
else
{
smtp.QueueWorkItem(new WorkItemCallback(threadProc), reversedWeights);
}
}
smtp.WaitForIdle();
smtp.Shutdown();
//double strengthRatio = ((double)weights[0].Wins + (double)weights[0].Draws / 2) / numberOfGames;
//return strengthRatio > 0.5 ? 1 : -1;
return weights[0].Wins + 1/2 * weights[0].Draws;
}
开发者ID:KamikazeBVB,项目名称:Checkers-and-Reversi,代码行数:25,代码来源:Program.cs
示例14: 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();
}
开发者ID:amibar,项目名称:SmartThreadPool,代码行数:30,代码来源:TestWIGConcurrencyChanges.cs
示例15: ExceptionThrowing
public void ExceptionThrowing()
{
SmartThreadPool _smartThreadPool = new SmartThreadPool();
DivArgs divArgs = new DivArgs();
divArgs.x = 10;
divArgs.y = 0;
IWorkItemResult wir =
_smartThreadPool.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();
}
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:27,代码来源:TestExceptions.cs
示例16: ExceptionReturning
public void ExceptionReturning()
{
bool success = true;
SmartThreadPool _smartThreadPool = new SmartThreadPool();
DivArgs divArgs = new DivArgs();
divArgs.x = 10;
divArgs.y = 0;
IWorkItemResult wir =
_smartThreadPool.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);
}
开发者ID:jogibear9988,项目名称:smartthreadpool,代码行数:27,代码来源:TestExceptions.cs
示例17: TimeoutInProgressWorkItemWithSample
public void TimeoutInProgressWorkItemWithSample()
{
bool timedout = false;
ManualResetEvent waitToStart = new ManualResetEvent(false);
ManualResetEvent waitToComplete = new ManualResetEvent(false);
SmartThreadPool stp = new SmartThreadPool();
IWorkItemResult wir = stp.QueueWorkItem(
new WorkItemInfo() { Timeout = 500 },
state =>
{
waitToStart.Set();
Thread.Sleep(1000);
timedout = SmartThreadPool.IsWorkItemCanceled;
waitToComplete.Set();
return null;
});
waitToStart.WaitOne();
waitToComplete.WaitOne();
Assert.IsTrue(timedout);
stp.Shutdown();
}
开发者ID:laoqiuChina,项目名称:SmartThreadPool,代码行数:26,代码来源:TestWorkItemTimeout.cs
示例18: WebService
/// <summary>
/// Initializes a new instance of the <see cref="Sid.WebServices.WebService"/> class.
/// </summary>
/// <param name="sidModuleAssemblies">Names of assemblies to scan for SidModules.</param>
/// <param name="successHandler">SuccessHandler; this is a delegate that, if set,
/// executes as the last thing before the response hits the wire. It allows users to
/// set response headers.</param>
/// <param name="prefixes">The set of prefixes for the HttpListener class that Sid
/// wraps.</param>
public WebService(IEnumerable<Assembly> sidModuleAssemblies,
System.Func<IRequest, Uri, bool> IsValidOriginHandler, params string[] prefixes)
{
SetupJsonDefaults();
if (!HttpListener.IsSupported) {
throw new NotSupportedException("Not supported on this");
}
threadPool = new SmartThreadPool();
if (prefixes == null || prefixes.Length == 0) {
throw new ArgumentException("prefixes");
}
foreach (var s in prefixes) {
listener.Prefixes.Add(s);
}
methodDispatcher = new RestfulMethodDispatcher(sidModuleAssemblies) {
IsValidOrigin = IsValidOriginHandler,
};
listener.Start();
}
开发者ID:scoutmedia,项目名称:Sid,代码行数:34,代码来源:WebService.cs
示例19: Test
public void Test()
{
_requestReceived = new ManualResetEvent(false);
/*setup + start listening*/
var stub = new SipReceivedMessageProcessorStub(OnRequestReceived, (s,e) => { });
var listeningPoint = new IPEndPoint(TestConstants.MyIpAddress, 33333);
var f = new SipFactory();
var stp = new SmartThreadPool();
stp.Start();
var provider = new SipContextSource(listeningPoint, stp);
provider.AddListener(null);
provider.Start();
/*send a message to the listener*/
var send = new SipRequestBuilder().Build();
var requestBytes = SipFormatter.FormatMessage(send);
var udpClient = new UdpClient();
udpClient.Send(requestBytes, requestBytes.Length, listeningPoint);
_requestReceived.WaitOne();
var oc = ObjectComparer.Create();
var received = stub.Requests.First();
oc.Compare(received, send);
Assert.True(oc.Differences.Count == 0, oc.DifferencesString);
}
开发者ID:HNeukermans,项目名称:Hallo,代码行数:32,代码来源:UdpSipListenerTests.cs
示例20: TestJoin
public void TestJoin()
{
SmartThreadPool stp = new SmartThreadPool();
SafeCounter sc = new SafeCounter();
stp.Join(
sc.Increment,
sc.Increment,
sc.Increment);
Assert.AreEqual(3, sc.Counter);
for (int j = 0; j < 10; j++)
{
sc.Reset();
Action[] actions = new Action[1000];
for (int i = 0; i < actions.Length; i++)
{
actions[i] = sc.Increment;
}
stp.Join(actions);
Assert.AreEqual(actions.Length, sc.Counter);
}
stp.Shutdown();
}
开发者ID:MattHoneycutt,项目名称:stp,代码行数:30,代码来源:TestParallelMethods.cs
注:本文中的Amib.Threading.SmartThreadPool类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论