本文整理汇总了C#中System.Threading.Semaphore.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# Semaphore.Dispose方法的具体用法?C# Semaphore.Dispose怎么用?C# Semaphore.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Semaphore
的用法示例。
在下文中一共展示了Semaphore.Dispose方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoStart
protected override void DoStart()
{
if (m_Prefixes.Count==0)
throw new WaveException(StringConsts.SERVER_NO_PREFIXES_ERROR.Args(Name));
if (!s_Servers.Register(this))
throw new WaveException(StringConsts.SERVER_COULD_NOT_GET_REGISTERED_ERROR.Args(Name));
try
{
if (m_Gate!=null)
if (m_Gate is Service)
((Service)m_Gate).Start();
if (m_Dispatcher==null)
m_Dispatcher = new WorkDispatcher(this);
m_Dispatcher.Start();
m_AcceptSemaphore = new Semaphore(m_ParallelAccepts, m_ParallelAccepts);
m_WorkSemaphore = new Semaphore(m_ParallelWorks, m_ParallelWorks);
m_AcceptThread = new Thread(acceptThreadSpin);
m_AcceptThread.Name = "{0}-AcceptThread".Args(Name);
m_InstrumentationThread = new Thread(instrumentationThreadSpin);
m_InstrumentationThread.Name = "{0}-InstrumentationThread".Args(Name);
m_InstrumentationThreadWaiter = new AutoResetEvent(false);
m_Listener = new HttpListener();
foreach(var prefix in m_Prefixes)
m_Listener.Prefixes.Add(prefix);
BeforeListenerStart(m_Listener);
m_Listener.Start();
AfterListenerStart(m_Listener);
m_Listener.IgnoreWriteExceptions = m_IgnoreClientWriteErrors;
if (m_KernelHttpQueueLimit!=DEFAULT_KERNEL_HTTP_QUEUE_LIMIT)
PlatformUtils.SetRequestQueueLimit(m_Listener, m_KernelHttpQueueLimit);
}
catch
{
closeListener();
if (m_AcceptSemaphore!=null) { m_AcceptSemaphore.Dispose(); m_AcceptSemaphore = null;}
if (m_WorkSemaphore!=null) { m_WorkSemaphore.Dispose(); m_WorkSemaphore = null;}
if (m_AcceptThread!=null) { m_AcceptThread = null;}
if (m_Dispatcher!=null) m_Dispatcher.WaitForCompleteStop();
if (m_Gate!=null && m_Gate is Service)
((Service)m_Gate).WaitForCompleteStop();
s_Servers.Unregister(this);
throw;
}
m_InstrumentationThread.Start();
m_AcceptThread.Start();
}
示例2: DoWorkCore
protected override string DoWorkCore()
{
//初始化信号量,按照读取的总秒数
m_semaphore = new Semaphore(0, this.m_endSecond - this.m_startSecond);
try
{
int secondsCount = 0;
while (m_semaphore.WaitOne())
{
secondsCount++;
if (this.m_endSecond - this.m_startSecond <= secondsCount)
{
break;
}
}
}
catch (Exception e)
{
return e.Message + "\r\n" + e.StackTrace;
}
finally
{
try
{
m_semaphore.Dispose();
}
catch
{
}
}
if (string.IsNullOrEmpty(this.m_lastResult))
return string.Empty;
return this.LastResult;
}