Ejemplo n.º 1
0
        /// <summary>
        /// This member overrides Component.Dispose.
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                GC.SuppressFinalize(this);
            }

            if (m_running)
            {
                Stop();
            }

            if (m_callbackHandle.IsAllocated)
            {
                m_callbackHandle.Free();
            }

            // stop worker thread
            m_disposing = true;
            m_waitHandle.Set();

            m_waitHandle.Close();

            base.Dispose(disposing);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// When overridden in a derived class, releases the unmanaged resources used by the LargeIntervalTimer, and optionally releases the managed resources.
        /// </summary>
        public void Dispose()
        {
            lock (m_interlock)
            {
                m_disposing = true;

                if (Enabled)
                {
                    Enabled = false;
                }

                if (m_quitHandle != null)
                {
                    m_quitHandle.Set();
                    m_quitHandle.Close();
                    m_quitHandle = null;
                }
            }
        }
Ejemplo n.º 3
0
        private void InternalThreadProc(object state)
        {
            ThreadCount++;

            int             source;
            string          eventName  = Guid.NewGuid().ToString();
            EventWaitHandle waitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, eventName);

            if (TestCondition == 0)
            {
                Thread.Sleep(1000);
            }

            try
            {
                while (m_enabled)
                {
                    if (TestCondition == 1)
                    {
                        Thread.Sleep(1000);
                    }

                    if (m_disposing)
                    {
                        return;
                    }

                    if (TestCondition == 2)
                    {
                        Thread.Sleep(1000);
                    }

                    if (m_useFirstTime)
                    {
                        Notify.RunAppAtTime(string.Format(@"\\.\Notifications\NamedEvents\{0}", eventName), m_firstTime);
                        m_useFirstTime = false;
                    }
                    else
                    {
                        // set up the next event
                        Notify.RunAppAtTime(string.Format(@"\\.\Notifications\NamedEvents\{0}", eventName), DateTime.Now.Add(m_interval));
                        m_firstTime = DateTime.MinValue;
                    }

                    if (TestCondition == 3)
                    {
                        Thread.Sleep(1000);
                    }

                    if (m_disposing)
                    {
                        return;
                    }
                    source = OpenNETCF.Threading.EventWaitHandle.WaitAny(new WaitHandle[] { waitHandle, m_quitHandle });

                    if (TestCondition == 4)
                    {
                        Thread.Sleep(1000);
                    }

                    // see if it's the event
                    if (source == 0)
                    {
                        m_cachedEnabled = null;

                        // fire the event if we have a listener
                        if (Tick != null)
                        {
                            // we need to decouple this call from the current thread or the lock will do nothing
                            ThreadPool.QueueUserWorkItem(new WaitCallback(
                                                             delegate
                            {
                                Tick(this, null);
                            }));
                        }

                        if (TestCondition == 5)
                        {
                            Thread.Sleep(1000);
                        }

                        if (OneShot)
                        {
                            if (TestCondition == 6)
                            {
                                Thread.Sleep(1000);
                            }

                            if (m_cachedEnabled != null)
                            {
                                if (TestCondition == 7)
                                {
                                    Thread.Sleep(1000);
                                }
                                m_enabled = (m_cachedEnabled == true);
                                if (TestCondition == 8)
                                {
                                    Thread.Sleep(1000);
                                }
                            }
                            else
                            {
                                m_enabled = false;
                            }
                        }
                    }
                    else
                    {
                        m_enabled = false;
                    }
                }
            }
            finally
            {
                waitHandle.Close();
                ThreadCount--;
                if (ThreadCount == 0)
                {
                    m_quitHandle.Reset();
                }
            }
        }