本文整理汇总了C#中WorkerThread.join方法的典型用法代码示例。如果您正苦于以下问题:C# WorkerThread.join方法的具体用法?C# WorkerThread.join怎么用?C# WorkerThread.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkerThread
的用法示例。
在下文中一共展示了WorkerThread.join方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
private void run(WorkerThread thread)
{
ThreadPoolWorkItem workItem = null;
while(true)
{
lock(this)
{
if(workItem != null)
{
Debug.Assert(_inUse > 0);
--_inUse;
if(_workItems.Count == 0)
{
thread.setState(Ice.Instrumentation.ThreadState.ThreadStateIdle);
}
}
workItem = null;
while(_workItems.Count == 0)
{
if(_destroyed)
{
return;
}
if(_threadIdleTime > 0)
{
if(!System.Threading.Monitor.Wait(this, _threadIdleTime * 1000) && _workItems.Count == 0) // If timeout
{
if(_destroyed)
{
return;
}
else if(_serverIdleTime == 0 || _threads.Count > 1)
{
//
// If not the last thread or if server idle time isn't configured,
// we can exit. Unlike C++/Java, there's no need to have a thread
// always spawned in the thread pool because all the IO is done
// by the .NET thread pool threads. Instead, we'll just spawn a
// new thread when needed (i.e.: when a new work item is queued).
//
if(_instance.traceLevels().threadPool >= 1)
{
string s = "shrinking " + _prefix + ": Size=" + (_threads.Count - 1);
_instance.initializationData().logger.trace(
_instance.traceLevels().threadPoolCat, s);
}
_threads.Remove(thread);
_instance.asyncIOThread().queue(() =>
{
thread.join();
});
return;
}
else
{
Debug.Assert(_serverIdleTime > 0 && _inUse == 0 && _threads.Count == 1);
if(!System.Threading.Monitor.Wait(this, _serverIdleTime * 1000) &&
_workItems.Count == 0)
{
if(!_destroyed)
{
_workItems.Enqueue(() =>
{
try
{
_instance.objectAdapterFactory().shutdown();
}
catch(Ice.CommunicatorDestroyedException)
{
}
});
}
}
}
}
}
else
{
System.Threading.Monitor.Wait(this);
}
}
Debug.Assert(_workItems.Count > 0);
workItem = _workItems.Dequeue();
Debug.Assert(_inUse >= 0);
++_inUse;
thread.setState(Ice.Instrumentation.ThreadState.ThreadStateInUseForUser);
if(_sizeMax > 1 && _inUse == _sizeWarn)
{
string s = "thread pool `" + _prefix + "' is running low on threads\n"
+ "Size=" + _size + ", " + "SizeMax=" + _sizeMax + ", " + "SizeWarn=" + _sizeWarn;
_instance.initializationData().logger.warning(s);
}
//.........这里部分代码省略.........