private void Form1_FormClosing(object sender, FormClosingEventArgs e) { for (int i = 0; i < thd.Count; i++) { thd[i].Abort(); } Sem.Dispose(); }
protected override void Dispose(bool disposing) { if (disposing) { _ThrottlingSemaphore?.Dispose(); _ThrottlingSemaphore = null; } base.Dispose(disposing); }
public static Semaphore OpenExisting(string name) { ValidateName(name); bool created; Semaphore s = new Semaphore(0, 0, name, out created); if (created) { //semaphore doesnt already exist s.Dispose(true); throw new WaitHandleCannotBeOpenedException(); } return(s); }
public static bool TryOpenExisting(string name, out Semaphore result) { ValidateName(name); bool created; Semaphore s = new Semaphore(0, 0, name, out created); if (created) { //semaphore doesnt already exist s.Dispose(true); result = null; return(false); } result = s; return(true); }
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(); }
public void Dispose() { _ThrottlingSemaphore?.Dispose(); _ThrottlingSemaphore = null; }
protected override void OnStop() { // watcher.Stop(); sem.Dispose(); }
public void Dispose() { _writeLock?.Dispose(); _readLock?.Dispose(); }
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; }