Ejemplo n.º 1
0
 public void Start()
 {
     socket_.Connect(Transport.TCP, settings_.QueryServerAddress);
     receiver_thread_ = receiver_thread_factory_
                        .CreateThread(GetResponse);
     running_ = true;
     receiver_thread_.Start();
 }
        public PausingWrapper(Action pausableMethod, IThreadFactory simpleThreadFactory)
        {
            this.pausableMethod = pausableMethod;

            //Note: this is deliberately not a background thread, since this could potentially cause slowdowns due to the OS not scheduling this thread fast enough
            thread = simpleThreadFactory.CreateThread(simulationThread);
            thread.Start();
        }
Ejemplo n.º 3
0
        private void StartAsyncProcessing()
        {
            _processingActive = true;
#if NETFX_CORE
            if (_threadPoolSupported)
            {
                try
                {
                    ThreadPool.RunAsync(ProcessRequestsAsync);
                }
                catch (NotSupportedException)
                {
                    _threadPoolSupported = false;
                }
            }

            if (!_threadPoolSupported)
            {
                var e = OnAsyncFailed;
                if (e != null)
                {
                    e();
                }
            }
#else
            if (_threadPoolSupported)
            {
                try
                {
                    _threadPoolSupported = ThreadPool.QueueUserWorkItem(ProcessRequestsAsync);
                }
                catch (NotSupportedException)
                {
                    _threadPoolSupported = false;
                }
            }

            if (!_threadPoolSupported)
            {
                if (_dedicatedThread != null)
                {
                    _waitHandle.Set();
                    return;
                }

                try
                {
                    if (_waitHandle == null)
                    {
                        _waitHandle = new AutoResetEvent(true);
                    }

                    var t = _threadFactory.CreateThread("Pathing", ProcessRequestsAsyncDedicated);
                    t.IsBackground = true;

                    _dedicatedThread = t;
                    t.Start();
                }
                catch
                {
                    this.runAsync = false;

                    if (_waitHandle != null)
                    {
                        _waitHandle.Close();
                    }

                    _processingActive = false;
                    _dedicatedThread  = null;
                    _waitHandle       = null;

                    var e = OnAsyncFailed;
                    if (e != null)
                    {
                        e();
                    }
                }
            }
#endif
        }