private static void Run(int n, int threadCount) { Dispatcher d = new Dispatcher(threadCount, "ccr pool"); DispatcherQueue dq = new DispatcherQueue("disp", d); Port<int> p1 = new Port<int>(), p2 = new Port<int>(); EventWaitHandle done1 = new AutoResetEvent(false), done2 = new AutoResetEvent(false); PingPonger pp1 = new PingPonger(done1, n, p2), pp2 = new PingPonger(done2, n, p1); Arbiter.Activate(dq, Arbiter.Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup(Arbiter.Receive(true, p1, pp1.Update)), new ConcurrentReceiverGroup())); Arbiter.Activate(dq, Arbiter.Interleave( new TeardownReceiverGroup(), new ExclusiveReceiverGroup(Arbiter.Receive(true, p2, pp2.Update)), new ConcurrentReceiverGroup())); p1.Post(0); EventWaitHandle.WaitAll(new[] { done1, done2 }); dq.Dispose(); d.Dispose(); }
public void StuffAfterDipose() { Dispatcher d = new Dispatcher (); var dq = new DispatcherQueue ("foo", d); d.Dispose (); dq.Dispose (); Assert.IsTrue (dq.IsDisposed, "#1"); try { dq.Enqueue (Arbiter.FromHandler( () => { Console.WriteLine ("ff"); })); Assert.Fail ("#2"); } catch (ObjectDisposedException) {} d = new Dispatcher (1, ThreadPriority.Normal, DispatcherOptions.SuppressDisposeExceptions, "foo"); dq = new DispatcherQueue ("foo", d); d.Dispose (); dq.Dispose (); Assert.IsTrue (dq.IsDisposed, "#3"); Assert.IsFalse (dq.Enqueue (Arbiter.FromHandler( () => {})), "#4"); Assert.AreEqual (0, dq.ScheduledTaskCount, "#5"); }
/// <summary> /// This is a helper mehtod that connects the Scribbler on the specified /// COM port. It waits for the connection to complete, and re-throws any /// exceptions generated by the Scribbler service. /// </summary> /// <param name="comPort"></param> private static void connectWaitForScribbler(string comPort) { ManualResetEvent evt = new ManualResetEvent(false); waitForService(new ServiceInfoType(scribbler.Contract.Identifier), delegate(ServiceInfoType info) { brickService = info; evt.Set(); }); evt.WaitOne(Params.DefaultRecieveTimeout, false); if (brickService == null) throw new MyroInitException("Could not find Scribbler service"); var scribPort = DssEnvironment.ServiceForwarder<scribbler.ScribblerOperations>(new Uri(brickService.Service)); DispatcherQueue queue = new DispatcherQueue("init", new Dispatcher()); try { if (comPort != null) { int comNumber; if (comPort.ToLower().StartsWith("com")) comNumber = Int32.Parse(comPort.Substring(3)); else throw new MyroInitException("COM port string must be of the format com2, com5, etc."); RSUtils.ReceiveSync(queue, scribPort.Replace(new scribbler.ScribblerState() { ComPort = comNumber }), Params.DefaultRecieveTimeout); } DssEnvironment.LogInfo("calling reconnect..."); RSUtils.ReceiveSync(queue, scribPort.Reconnect(), Params.DefaultRecieveTimeout); DssEnvironment.LogInfo("reconnect returned"); } catch (Exception) { throw; } finally { queue.Dispose(); } }