当前位置: 首页>>代码示例>>C#>>正文


C# Semaphore.Dispose方法代码示例

本文整理汇总了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();
      }
开发者ID:sergey-msu,项目名称:nfx,代码行数:67,代码来源:WaveServer.cs

示例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;
        }
开发者ID:K-Library-NET,项目名称:PopcornStudios,代码行数:37,代码来源:FastDataReadingStepHandler.cs


注:本文中的System.Threading.Semaphore.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。