Ejemplo n.º 1
0
        private void StopTimer()
        {
            isStart = false;

            ClearMessage();
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < timerLst.Count; i++)
            {
                try
                {
                    // System.Timers.Timer aTimer = timerLst[i];
                    NamedTimer aTimer = timerLst[i];

                    //aTimer.Enabled = false;
                    aTimer.Stop();
                    aTimer.Dispose();
                    aTimer = null;

                    sb.Append("\r\n >>>>>>>>>>>>>>>>>>>      STOP TIMER(" + i + ") ");
                }
                catch (Exception ex)
                {
                    sb.Append("\r\n -----------> ERROR STOP TIMER(" + i + "): " + ex.Message);
                }
            }

            AddMessage(sb.ToString());
        }
Ejemplo n.º 2
0
        private void StartTimer()
        {
            ClearMessage();


            StringBuilder sb = new StringBuilder();

            isStart  = true;
            timerLst = new List <NamedTimer>();
            for (int i = 0; i < 1; i++)
            {
                // Create a timer with a two second interval.
                NamedTimer aTimer = new NamedTimer("TIMER_" + i);

                aTimer.Interval  = GetMiliseconds();     // (1000 * 1); //1 sec
                aTimer.Elapsed  += OnTimedEvent;
                aTimer.AutoReset = !AutoResetCB.Checked; //aTimer.AutoReset = true;
                // aTimer.Enabled = true;
                aTimer.Start();


                sb.Append("\r\n <<<<<<<<<<<<<<<<        START TIMER(" + i + ") ");

                timerLst.Add(aTimer);
            }

            AddMessage(sb.ToString());
        }
Ejemplo n.º 3
0
        private async void OnTimedEvent(Object source, ElapsedEventArgs e)
        {
            try
            {
                NamedTimer timer = source as NamedTimer;
                //   AddMessage("------- (" + timer.name + ") Loop  -------");

                if (isStart == false)
                {
                    return;
                }


                for (int i = 0; i < GetCountOfPostRequestTB(); i++)
                {
                    await SendPostRequest(i);
                }
            }
            catch (Exception ex)
            {
                AddMessage("Error (OnTimedEvent): " + ex.Message);
            }
        }