コード例 #1
0
ファイル: Robot.cs プロジェクト: yingted/Myro
        /// <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();
            }
        }
コード例 #2
0
ファイル: CommandWindow.xaml.cs プロジェクト: yingted/Myro
 /// <summary>
 /// This must be called to stop threads and the DispatcherQueue.
 /// </summary>
 public void Dispose()
 {
     if (stdout != null)
     {
         stdout.Close();
         stdoutpipe.Close();
         stderr.Close();
         stderrpipe.Close();
     }
     if (readThreadOut != null && readThreadOut.IsAlive)
     {
         readThreadOut.Join();
     }
     if (readThreadErr != null && readThreadErr.IsAlive)
     {
         readThreadErr.Join();
     }
     if (commandDispatcherQueue != null)
     {
         commandDispatcherQueue.Dispose();
     }
 }
コード例 #3
0
ファイル: DriveControl.xaml.cs プロジェクト: yingted/Myro
 public void Dispose()
 {
     //Console.WriteLine("****** Unloading ********");
     taskQueue.Dispose();
 }
コード例 #4
0
 public void Dispose()
 {
     taskQueue.Dispose();
 }
コード例 #5
0
 public void Dispose()
 {
     queue.Dispose();
 }
コード例 #6
0
        private void SetupOutMessagesOnRelayThreads(RelayNodeConfig newConfiguration)
        {
            //if it was off and is now on, or if it was on and the number of threads changed
            bool setupNewOutMessages = (newConfiguration.OutMessagesOnRelayThreads && configuration.OutMessagesOnRelayThreads == false) ||
                                       (configuration.OutMessagesOnRelayThreads && newConfiguration.OutMessagesOnRelayThreads &&
                                        newConfiguration.NumberOfOutMessageThreads != configuration.NumberOfOutMessageThreads);

            Dispatcher      oldOutDispatcher   = outDispatcher;
            DispatcherQueue oldOutMessageQueue = outMessageQueue;

            if (setupNewOutMessages)
            {
                try
                {
                    const string outThreadsName = "DataRelayNodeOUT";

                    outMessagePort  = new Port <RelayMessageAsyncResult>();                   //atomic
                    outMessagesPort = new Port <RelayMessageListAsyncResult>();               //atomic

                    if (newConfiguration.NumberOfOutMessageThreads > 0)
                    {
                        outDispatcher = new Dispatcher(newConfiguration.NumberOfOutMessageThreads, ThreadPriority.Normal, true, outThreadsName);
                    }
                    else
                    {
                        outDispatcher = new Dispatcher {
                            Name = outThreadsName
                        };
                    }

                    outMessageQueue = new DispatcherQueue("DataRelayDispatcherQueueOUT", outDispatcher, TaskExecutionPolicy.ConstrainQueueDepthThrottleExecution, newConfiguration.MaximumOutMessageQueueDepth);

                    Arbiter.Activate(outMessageQueue,
                                     Arbiter.ReceiveWithIterator(true, outMessagePort, HandleOutMessage));
                    Arbiter.Activate(outMessageQueue,
                                     Arbiter.ReceiveWithIterator(true, outMessagesPort, HandleOutMessages));
                }
                catch (Exception e)
                {
                    if (log.IsErrorEnabled)
                    {
                        log.ErrorFormat("Error setting up Out Message Threads on RelayNode: {0}", e);
                    }
                    throw;
                }
            }

            if (newConfiguration.OutMessagesOnRelayThreads == false)
            {
                outMessagePort  = null;
                outMessagesPort = null;
                if (oldOutDispatcher != null)
                {
                    oldOutDispatcher.Dispose();
                }
                if (oldOutMessageQueue != null)
                {
                    oldOutMessageQueue.Dispose();
                }
            }
        }
コード例 #7
0
ファイル: SimulatorDisplay.xaml.cs プロジェクト: yingted/Myro
 /// <summary>
 /// Stop DispatcherQueues and threads.
 /// </summary>
 public void Dispose()
 {
     queue.Dispose();
     throttledQueue.Dispose();
     shouldStay = false;
 }