示例#1
0
            public void Run()
            {
                Debug.Assert(_threadPool != null);
                Debug.Assert(_thread != null);
                //
                // Set the default synchronization context to allow async/await to run
                // continuations on the thread pool.
                //
                SynchronizationContext.SetSynchronizationContext(new ThreadPoolSynchronizationContext(_threadPool));

                var threadStart = _threadPool._communicator.initializationData().threadStart;

                if (threadStart != null)
                {
                    try
                    {
                        threadStart();
                    }
                    catch (System.Exception ex)
                    {
                        string s = "thread hook start() method raised an unexpected exception in `";
                        s += _threadPool._prefix + "' thread " + _thread.Name + ":\n" + ex;
                        _threadPool._communicator.Logger.error(s);
                    }
                }

                try
                {
                    _threadPool.run(this);
                }
                catch (System.Exception ex)
                {
                    string s = "exception in `" + _threadPool._prefix + "' thread " + _thread.Name + ":\n" + ex;
                    _threadPool._communicator.Logger.error(s);
                }

                if (_observer != null)
                {
                    _observer.detach();
                }

                var threadStop = _threadPool._communicator.initializationData().threadStop;

                if (threadStop != null)
                {
                    try
                    {
                        threadStop();
                    }
                    catch (System.Exception ex)
                    {
                        string s = "thread hook stop() method raised an unexpected exception in `";
                        s += _threadPool._prefix + "' thread " + _thread.Name + ":\n" + ex;
                        _threadPool._communicator.Logger.error(s);
                    }
                }
            }
示例#2
0
            public void Run()
            {
                //
                // Set the default synchronization context to allow async/await to run
                // continuations on the thread pool.
                //
                SynchronizationContext.SetSynchronizationContext(new ThreadPoolSynchronizationContext(_threadPool));

                if (_threadPool._instance.initializationData().threadHook != null)
                {
                    try
                    {
                        _threadPool._instance.initializationData().threadHook.start();
                    }
                    catch (System.Exception ex)
                    {
                        string s = "thread hook start() method raised an unexpected exception in `";
                        s += _threadPool._prefix + "' thread " + _thread.Name + ":\n" + ex;
                        _threadPool._instance.initializationData().logger.error(s);
                    }
                }

                try
                {
                    _threadPool.run(this);
                }
                catch (System.Exception ex)
                {
                    string s = "exception in `" + _threadPool._prefix + "' thread " + _thread.Name + ":\n" + ex;
                    _threadPool._instance.initializationData().logger.error(s);
                }

                if (_observer != null)
                {
                    _observer.detach();
                }

                if (_threadPool._instance.initializationData().threadHook != null)
                {
                    try
                    {
                        _threadPool._instance.initializationData().threadHook.stop();
                    }
                    catch (System.Exception ex)
                    {
                        string s = "thread hook stop() method raised an unexpected exception in `";
                        s += _threadPool._prefix + "' thread " + _thread.Name + ":\n" + ex;
                        _threadPool._instance.initializationData().logger.error(s);
                    }
                }
            }
示例#3
0
文件: ThreadPool.cs 项目: pirater/ice
            public void Run()
            {
                if (_threadPool._instance.initializationData().threadHook != null)
                {
                    try
                    {
                        _threadPool._instance.initializationData().threadHook.start();
                    }
                    catch (System.Exception ex)
                    {
                        string s = "thread hook start() method raised an unexpected exception in `";
                        s += _threadPool._prefix + "' thread " + _thread.Name + ":\n" + ex;
                        _threadPool._instance.initializationData().logger.error(s);
                    }
                }

                try
                {
                    _threadPool.run(this);
                }
                catch (System.Exception ex)
                {
                    string s = "exception in `" + _threadPool._prefix + "' thread " + _thread.Name + ":\n" + ex;
                    _threadPool._instance.initializationData().logger.error(s);
                }

                if (_observer != null)
                {
                    _observer.detach();
                }

                if (_threadPool._instance.initializationData().threadHook != null)
                {
                    try
                    {
                        _threadPool._instance.initializationData().threadHook.stop();
                    }
                    catch (System.Exception ex)
                    {
                        string s = "thread hook stop() method raised an unexpected exception in `";
                        s += _threadPool._prefix + "' thread " + _thread.Name + ":\n" + ex;
                        _threadPool._instance.initializationData().logger.error(s);
                    }
                }
            }