本文整理汇总了C#中WorkerThread.start方法的典型用法代码示例。如果您正苦于以下问题:C# WorkerThread.start方法的具体用法?C# WorkerThread.start怎么用?C# WorkerThread.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WorkerThread
的用法示例。
在下文中一共展示了WorkerThread.start方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ThreadPool
//.........这里部分代码省略.........
// We use just one thread as the default. This is the fastest
// possible setting, still allows one level of nesting, and
// doesn't require to make the servants thread safe.
//
int size = properties.getPropertyAsIntWithDefault(_prefix + ".Size", 1);
if(size < 1)
{
string s = _prefix + ".Size < 1; Size adjusted to 1";
_instance.initializationData().logger.warning(s);
size = 1;
}
int sizeMax = properties.getPropertyAsIntWithDefault(_prefix + ".SizeMax", size);
if(sizeMax < size)
{
string s = _prefix + ".SizeMax < " + _prefix + ".Size; SizeMax adjusted to Size (" + size + ")";
_instance.initializationData().logger.warning(s);
sizeMax = size;
}
int sizeWarn = properties.getPropertyAsInt(_prefix + ".SizeWarn");
if(sizeWarn != 0 && sizeWarn < size)
{
string s = _prefix + ".SizeWarn < " + _prefix + ".Size; adjusted SizeWarn to Size (" + size + ")";
_instance.initializationData().logger.warning(s);
sizeWarn = size;
}
else if(sizeWarn > sizeMax)
{
string s = _prefix + ".SizeWarn > " + _prefix + ".SizeMax; adjusted SizeWarn to SizeMax ("
+ sizeMax + ")";
_instance.initializationData().logger.warning(s);
sizeWarn = sizeMax;
}
int threadIdleTime = properties.getPropertyAsIntWithDefault(_prefix + ".ThreadIdleTime", 60);
if(threadIdleTime < 0)
{
string s = _prefix + ".ThreadIdleTime < 0; ThreadIdleTime adjusted to 0";
_instance.initializationData().logger.warning(s);
threadIdleTime = 0;
}
_size = size;
_sizeMax = sizeMax;
_sizeWarn = sizeWarn;
_threadIdleTime = threadIdleTime;
int stackSize = properties.getPropertyAsInt(_prefix + ".StackSize");
if(stackSize < 0)
{
string s = _prefix + ".StackSize < 0; Size adjusted to OS default";
_instance.initializationData().logger.warning(s);
stackSize = 0;
}
_stackSize = stackSize;
_hasPriority = properties.getProperty(_prefix + ".ThreadPriority").Length > 0;
_priority = IceInternal.Util.stringToThreadPriority(properties.getProperty(_prefix + ".ThreadPriority"));
if(!_hasPriority)
{
_hasPriority = properties.getProperty("Ice.ThreadPriority").Length > 0;
_priority = IceInternal.Util.stringToThreadPriority(properties.getProperty("Ice.ThreadPriority"));
}
if(_instance.traceLevels().threadPool >= 1)
{
string s = "creating " + _prefix + ": Size = " + _size + ", SizeMax = " + _sizeMax + ", SizeWarn = " +
_sizeWarn;
_instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s);
}
_workItems = new Queue<ThreadPoolWorkItem>();
try
{
_threads = new List<WorkerThread>();
for(int i = 0; i < _size; ++i)
{
WorkerThread thread = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++);
if(_hasPriority)
{
thread.start(_priority);
}
else
{
thread.start(ThreadPriority.Normal);
}
_threads.Add(thread);
}
}
catch(System.Exception ex)
{
string s = "cannot create thread for `" + _prefix + "':\n" + ex;
_instance.initializationData().logger.error(s);
destroy();
joinWithAllThreads();
throw;
}
}
示例2: dispatch
public void dispatch(System.Action call, Ice.Connection con)
{
lock(this)
{
if(_destroyed)
{
throw new Ice.CommunicatorDestroyedException();
}
_workItems.Enqueue(() =>
{
dispatchFromThisThread(call, con);
});
System.Threading.Monitor.Pulse(this);
//
// If this is a dynamic thread pool which can still grow and if all threads are
// currently busy dispatching or about to dispatch, we spawn a new thread to
// execute this new work item right away.
//
if(_threads.Count < _sizeMax &&
(_inUse + _workItems.Count) > _threads.Count &&
!_destroyed)
{
if(_instance.traceLevels().threadPool >= 1)
{
string s = "growing " + _prefix + ": Size = " + (_threads.Count + 1);
_instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s);
}
try
{
WorkerThread t = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++);
if(_hasPriority)
{
t.start(_priority);
}
else
{
t.start(ThreadPriority.Normal);
}
_threads.Add(t);
}
catch(System.Exception ex)
{
string s = "cannot create thread for `" + _prefix + "':\n" + ex;
_instance.initializationData().logger.error(s);
}
}
}
}
示例3: execute
execute(ThreadPoolWorkItem workItem)
{
_m.Lock();
try
{
Debug.Assert(!_destroyed);
if(_workItems.Count == 0)
{
_m.Notify();
}
_workItems.Enqueue(workItem);
//
// If this is a dynamic thread pool which can still grow and if all threads are
// currently busy dispatching or about to dispatch, we spawn a new thread to
// execute this new work item right away.
//
if(_threads.Count < _sizeMax &&
(_inUse + _workItems.Count) > _threads.Count &&
!_destroyed)
{
if(_instance.traceLevels().threadPool >= 1)
{
string s = "growing " + _prefix + ": Size = " + (_threads.Count + 1);
_instance.initializationData().logger.trace(_instance.traceLevels().threadPoolCat, s);
}
try
{
WorkerThread t = new WorkerThread(this, _threadPrefix + "-" + _threadIndex++);
if(_hasPriority)
{
t.start(_priority);
}
else
{
t.start(ThreadPriority.Normal);
}
_threads.Add(t);
}
catch(System.Exception ex)
{
string s = "cannot create thread for `" + _prefix + "':\n" + ex;
_instance.initializationData().logger.error(s);
}
}
}
finally
{
_m.Unlock();
}
}