示例#1
0
        protected override void ThreadFunction()
        {
            CommandInfo cmd = null;

            try
            {
                Empty.Reset();

                lock (this)
                {
                    while (m_Queue.Count == 0)
                    {
                        Empty.Set();
                        Monitor.Wait(this, DEFAULT_TIMEOUT);
                    }
                }

                cmd = (CommandInfo)m_Queue[0];
                m_Queue.RemoveAt(0);

                if (cmd != null)
                {
                    SQL.ExecuteNonQuery(cmd.Command);
                }
                cmd.FireSuccess();
            }
            catch (ThreadAbortException)
            {
                Debug.Assert(m_Queue.Count == 0, "Queue is not empty. Call Empty.WaitOne() first.");
                //No problem
                //exit signal
            }
            catch (ThreadInterruptedException)
            {
                Debug.Assert(m_Queue.Count == 0, "Queue is not empty. Call Empty.WaitOne() first.");
                //No problem
                //join signal
            }
            catch (Exception ex)
            {
                Trace.WriteLine(ex, "SQLWorkerThread");

                if (cmd == null)
                {
                    return;
                }

                if (cmd.HandlesError)
                {
                    cmd.FireError(ex);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                cmd.DisposeSf();
            }
        }