本文整理汇总了C#中Amib.Threading.SmartThreadPool.Start方法的典型用法代码示例。如果您正苦于以下问题:C# SmartThreadPool.Start方法的具体用法?C# SmartThreadPool.Start怎么用?C# SmartThreadPool.Start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Amib.Threading.SmartThreadPool
的用法示例。
在下文中一共展示了SmartThreadPool.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: 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");
}
示例3: BaseApproach
public BaseApproach(int autoCompleteAfterNChars, StandardEvalOutput evalOutput, PrefixProfile queryPrefixProfile)
{
_autoCompleteAfterNChars = autoCompleteAfterNChars;
_evalOutput = evalOutput;
_queryPrefixProfile = queryPrefixProfile;
_evalThreadPool = new SmartThreadPool(1000, 6);
_evalThreadPool.Start(); // Setup and start the threadpool
}
示例4: IrrManager
public IrrManager(Viewer viewer, int _id)
: base(viewer, _id)
{
ChangeWorkDirectory(Util.ModelFolder);
asset_max_threads = Reference.Viewer.Config.Source.Configs["Startup"].GetInt("asset_max_threads", 1);
asset_fetch_retry = Reference.Viewer.Config.Source.Configs["Startup"].GetInt("asset_fetch_retry", 2);
requestingThreadPool = new SmartThreadPool(120 * 1000, asset_max_threads);
requestingThreadPool.Start();
}
示例5: Start
/// <summary>
/// Starts the tasks execution.
/// </summary>
/// <returns>If has reach the timeout false, otherwise true.</returns>
public override bool Start()
{
base.Start();
m_threadPool = new SmartThreadPool();
try
{
m_threadPool.MinThreads = MinThreads;
m_threadPool.MaxThreads = MaxThreads;
var workItemResults = new IWorkItemResult[Tasks.Count];
for (int i = 0; i < Tasks.Count; i++)
{
var t = Tasks[i];
workItemResults[i] = m_threadPool.QueueWorkItem(new WorkItemCallback(Run), t);
}
m_threadPool.Start();
// Timeout was reach?
if (!m_threadPool.WaitForIdle(Timeout.TotalMilliseconds > int.MaxValue ? int.MaxValue : Convert.ToInt32(Timeout.TotalMilliseconds)))
{
if (m_threadPool.IsShuttingdown)
{
return true;
}
else
{
m_threadPool.Cancel(true);
return false;
}
}
foreach (var wi in workItemResults)
{
Exception ex;
wi.GetResult(out ex);
if (ex != null)
{
throw ex;
}
}
return true;
}
finally
{
m_threadPool.Shutdown(true, 1000);
m_threadPool.Dispose();
IsRunning = false;
}
}
示例6: Parse
public Character Parse(Character character, bool force)
{
stopwatch.Reset();
Stopwatch watch = new Stopwatch();
watch.Start();
_current = character;
// Only parse the character once a day unless forced
if (character.LastParseDate.HasValue &&
character.LastParseDate.Value.AddDays(7) > DateTime.Now && !force)
{
return character;
}
ParseCharacterInformation(character);
//character.Achievements.Clear();
string mainAchievementPageUrl = string.Format("http://{2}.battle.net/wow/en/character/{0}/{1}/achievement", character.Server, character.Name, character.Region);
HtmlDocument doc = DownloadPage(mainAchievementPageUrl);
List<AchievedAchievement> achievements = new List<AchievedAchievement>();
ProcessPageForAchievements(doc.DocumentNode, character);
pagesToParse = new List<HtmlDocument>();
IList<string> extraPages = FindSubAchievementPages(doc.DocumentNode);
SmartThreadPool pool = new SmartThreadPool();
foreach (string pageUrl in extraPages)
{
pool.QueueWorkItem(new WorkItemCallback(ProcessPageOnNewThread), pageUrl);
}
pool.Start();
pool.WaitForIdle();
try
{
foreach (HtmlDocument page in pagesToParse)
{
ProcessPageForAchievements(page.DocumentNode, character);
}
}
catch (IndexOutOfRangeException)
{
}
character.LastParseDate = DateTime.Now;
character.CurrentPoints = character.TotalAchievementPoints;
watch.Stop();
return character;
}
示例7: QueueWorkItem_WhenMaxIsNull_Queues
public void QueueWorkItem_WhenMaxIsNull_Queues()
{
var info = new STPStartInfo
{
MaxQueueLength = null,
};
var pool = new SmartThreadPool(info);
pool.Start();
var workItem = pool.QueueWorkItem<object>(ReturnNull);
// If rejected, an exception would have been thrown instead.
Assert.IsTrue(workItem.GetResult() == null);
}
示例8: StartSuspended
public void StartSuspended()
{
STPStartInfo stpStartInfo = new STPStartInfo();
stpStartInfo.StartSuspended = true;
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
stp.QueueWorkItem(new WorkItemCallback(this.DoWork));
Assert.IsFalse(stp.WaitForIdle(200));
stp.Start();
Assert.IsTrue(stp.WaitForIdle(200));
}
示例9: QueueWorkItem_WhenBiggerMaxIsSet_ThrowsExceptionWhenHit
public void QueueWorkItem_WhenBiggerMaxIsSet_ThrowsExceptionWhenHit()
{
Assert.Throws<QueueRejectedException>(() =>
{
var info = new STPStartInfo
{
MaxQueueLength = 5,
MinWorkerThreads = 5,
MaxWorkerThreads = 10,
};
var pool = new SmartThreadPool(info);
pool.Start();
try
{
// Pool starts with 5 available waiters.
pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // Taken by waiter immediately. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // New thread created, takes work item. Not queued.
pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
pool.QueueWorkItem(SleepForOneSecond); // No waiters available. Queued.
}
catch (QueueRejectedException e)
{
throw new Exception("Caught QueueRejectedException too early: ", e);
}
// All threads are busy, and queue is at its max. Throws.
pool.QueueWorkItem(SleepForOneSecond);
});
}
示例10: GetUploadDataThreadPoolInstance
public static SmartThreadPool GetUploadDataThreadPoolInstance()
{
if (uploadDataThreadPool == null)
{
lock (uploadDataThreadPoolLocker)
{
if (uploadDataThreadPool == null)
{
if (uploadDataThreadPoolStartInfo == null)
{
throw new Exception("线程池需要启动参数");
}
uploadDataThreadPool = new SmartThreadPool(uploadDataThreadPoolStartInfo);
uploadDataThreadPool.Start();
}
}
}
return uploadDataThreadPool;
}
示例11: GetCollectDataThreadPoolInstance
public static SmartThreadPool GetCollectDataThreadPoolInstance()
{
if (collectDataThreadPool == null)
{
lock (collectDataThreadPoolLocker)
{
if (collectDataThreadPool == null)
{
if (collectDataThreadPoolStartInfo == null)
{
throw new Exception("线程池需要启动参数");
}
collectDataThreadPool = new SmartThreadPool(collectDataThreadPoolStartInfo);
collectDataThreadPool.Start();
}
}
}
return collectDataThreadPool;
}
示例12: Concurrency
private void Concurrency(
int concurrencyPerWig,
int wigsCount,
int workItemsCount)
{
Console.WriteLine(
"Testing : concurrencyPerWig = {0}, wigsCount = {1}, workItemsCount = {2}",
concurrencyPerWig,
wigsCount,
workItemsCount);
_success = true;
_concurrencyPerWig = concurrencyPerWig;
_randGen = new Random(0);
STPStartInfo stpStartInfo = new STPStartInfo();
stpStartInfo.StartSuspended = true;
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
_concurrentOps = new int[wigsCount];
IWorkItemsGroup [] wigs = new IWorkItemsGroup[wigsCount];
for(int i = 0; i < wigs.Length; ++i)
{
wigs[i] = stp.CreateWorkItemsGroup(_concurrencyPerWig);
for(int j = 0; j < workItemsCount; ++j)
{
wigs[i].QueueWorkItem(new WorkItemCallback(this.DoWork), i);
}
wigs[i].Start();
}
stp.Start();
stp.WaitForIdle();
Assert.IsTrue(_success);
stp.Shutdown();
}
示例13: NotTestThreadsMaxStackSize
// Can't run this test, StackOverflowException crashes the application and can't be catched and ignored
//[Test]
public void NotTestThreadsMaxStackSize()
{
STPStartInfo stpStartInfo = new STPStartInfo()
{
MaxStackSize = 64 * 1024,
};
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
stp.Start();
IWorkItemResult<bool> wir = stp.QueueWorkItem(() => AllocateBufferOnStack(10 * 1024));
bool result = wir.GetResult();
Assert.IsTrue(result);
wir = stp.QueueWorkItem(() => AllocateBufferOnStack(1000 * 1024));
result = wir.GetResult();
Assert.IsFalse(result);
}
示例14: DoWork
public void DoWork(object [] states)
{
STPStartInfo stpStartInfo = new STPStartInfo();
stpStartInfo.StartSuspended = true;
SmartThreadPool smartThreadPool = new SmartThreadPool(stpStartInfo);
foreach(object state in states)
{
smartThreadPool.QueueWorkItem(new
WorkItemCallback(this.DoSomeWork), state);
}
// Start working on the work items in the queue
smartThreadPool.Start();
// Wait for the completion of all work items
smartThreadPool.WaitForIdle();
smartThreadPool.Shutdown();
}
示例15: CancelInQueueWorkItem
public void CancelInQueueWorkItem()
{
Assert.Throws<WorkItemCancelException>(() =>
{
STPStartInfo stpStartInfo = new STPStartInfo();
stpStartInfo.StartSuspended = true;
bool hasRun = false;
SmartThreadPool stp = new SmartThreadPool(stpStartInfo);
IWorkItemResult wir = stp.QueueWorkItem(
new WorkItemInfo() {Timeout = 500},
state =>
{
hasRun = true;
return null;
});
Assert.IsFalse(wir.IsCanceled);
Thread.Sleep(2000);
Assert.IsTrue(wir.IsCanceled);
stp.Start();
stp.WaitForIdle();
Assert.IsFalse(hasRun);
try
{
wir.GetResult();
}
finally
{
stp.Shutdown();
}
});
}