public CellIdCollector(Interfaces.ICellStorage storage, int dueTime, int period, bool alwaysOn)
        {
            //m_StopThread = false;
            //m_CurrentCellid = string.Empty;
            m_CellCollection = new Dictionary <string, GeoLocation>();
            m_Lock           = new object();
            m_DueTime        = dueTime;
            m_Period         = period;
            m_Storage        = storage;
            m_AlwaysOn       = alwaysOn;

            if (m_AlwaysOn)
            {
                //System.Threading.TimerCallback tcb = CellCollector;
                //m_Timer = new System.Threading.Timer(tcb, new object(), System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite);
                m_Thread      = new Thread(CellCollectorThread);
                m_Thread.Name = "CellCollectorThread";

                //m_Thread.IsBackground = true;
            }
            else
            {
                m_Timer                = new LargeIntervalTimer();
                m_Timer.OneShot        = false;                                     //run forever
                m_Timer.FirstEventTime = DateTime.Now.AddMilliseconds(m_DueTime);   //start in x seconds
                m_Timer.Interval       = TimeSpan.FromMilliseconds(m_Period);
                m_Timer.Tick          += Timer_Tick;
            }
        }
Esempio n. 2
0
        public void OneShotRaceTest()
        {
#if INTEGRATION_TEST
            for (int condition = 0; condition < 9; condition++)
            {
                // Create timer, set to some interval
                LargeIntervalTimer lit = new LargeIntervalTimer();
                lit.Interval = TimeSpan.FromSeconds(17);

                lit.OneShot = true;
                lit.Enabled = true;

                lit.Enabled = false;

                lit.OneShot = false;
                lit.Enabled = true;

                Thread.Sleep((int)lit.Interval.TotalMilliseconds + 3000);

                Assert.IsTrue(lit.Enabled);
                Assert.IsFalse(lit.OneShot);
                lit.Dispose();
            }
#else
            Assert.Inconclusive("INTEGRATION_TEST not defined - test not run");
#endif
        }
Esempio n. 3
0
        public void ThreadCountTest()
        {
#if INTEGRATION_TEST
            for (int condition = 0; condition < 9; condition++)
            {
                // Create timer, set to some interval
                LargeIntervalTimer lit = new LargeIntervalTimer();
                lit.Interval      = TimeSpan.FromSeconds(20);
                lit.OneShot       = true;
                lit.TestCondition = condition;

                for (int i = 0; i < 10; ++i)
                {
                    lit.Enabled = false;
                    lit.Enabled = true;
                    Thread.Sleep(0);
                }

                Assert.IsTrue(lit.ThreadCount == 1);
                Assert.IsTrue(lit.OneShot);

                lit.Dispose();
            }
#else
            Assert.Inconclusive("INTEGRATION_TEST not defined - test not run");
#endif
        }
Esempio n. 4
0
        public void IntervalValidValuesTest()
        {
            LargeIntervalTimer lit = new LargeIntervalTimer();

            // bugzilla 365
            TimeSpan expected = new TimeSpan(0, 45, 0);

            lit.Interval = expected;
            Assert.AreEqual(expected, lit.Interval);

            // minutes only
            expected     = new TimeSpan(0, 1, 0);
            lit.Interval = expected;
            Assert.AreEqual(expected, lit.Interval);

            // minutes and secs < 15
            expected     = new TimeSpan(0, 45, 10);
            lit.Interval = expected;
            Assert.AreEqual(expected, lit.Interval);

            // hours only
            expected     = new TimeSpan(2, 0, 0);
            lit.Interval = expected;
            Assert.AreEqual(expected, lit.Interval);
        }
        private void Dispose(bool ADisposing)
        {
            if (!m_Disposed)
            {
                // wenn true, alle managed und unmanaged resources mussen aufgelegt werden.
                if (ADisposing)
                {
                    //nix zu machen in moment
                }

                //Console.WriteLine("{0}: GPS-Thread beendet", DateTime.Now);

                lock (m_Lock)
                {
                    if (null != m_Thread)
                    {
                        m_StopThread = true;
                        m_Thread.Join();

                        Logger.Log("Thread {0} Stopped", m_Thread.ManagedThreadId);

                        m_Thread = null;
                    }

                    if (null != m_Timer)
                    {
                        m_Timer.Enabled = false;
                        Thread.Sleep(1000);
                        m_Timer.Dispose();
                        m_Timer = null;

                        Logger.Log("Timer Disposed");
                    }

                    m_CellCollection.Clear();
                    m_CellCollection = null;

                    Logger.Log("Cell Collection cleared");

                    if (null != m_StreamWriter)
                    {
                        m_StreamWriter.Flush();
                        m_StreamWriter.Close();
                        m_StreamWriter.Dispose();

                        Logger.Log("StreamWriter Closed and Disposed");
                    }

                    m_StreamWriter = null;
                }

                m_Lock = null;
            }

            m_Disposed = true;
        }
Esempio n. 6
0
        void EnabledThreadSafetyTick(object sender, EventArgs e)
        {
            LargeIntervalTimer lit = (LargeIntervalTimer)sender;

            m_ticks++;

            if (m_ticks == 1)
            {
                // re-enable the LIT once
                lit.Enabled = true;
            }
        }
Esempio n. 7
0
        public void EnabledThreadSafetyCheck()
        {
            LargeIntervalTimer lit = new LargeIntervalTimer();

            lit.Interval = TimeSpan.FromSeconds(25);
            lit.OneShot  = true;
            lit.Tick    += new EventHandler(EnabledThreadSafetyTick);
            // lit.TestCondition = -1;

            m_ticks     = 0;
            lit.Enabled = true;

            // wait for 1 tick period to pass
            Thread.Sleep(30000);
            Assert.AreEqual(1, m_ticks, "LIT didn't tick the first time");

            // wait for 1 tick period to pass
            Thread.Sleep(30000);
            Assert.AreEqual(2, m_ticks, "LIT didn't tick the second time");
        }
 public void ShutDown()
 {
     if (updateTimer != null)
     {
         updateTimer.Enabled = false;
         updateTimer = null;
     }
 }
Esempio n. 9
0
        public void IntervalLessThan15secondsTest()
        {
            LargeIntervalTimer lit = new LargeIntervalTimer();

            lit.Interval = new TimeSpan(0, 0, 10);
        }