Esempio n. 1
0
 void timer_Elapsed(object sender, EventArgs e)
 {
     sendSocket.SendTo(data, sendDataLength, SocketFlags.None, (EndPoint)remoteEP);
     packetSendNum++;
     if (!isSendRunning || (setSendNum != 0 && packetSendNum == setSendNum))
     {
         timer.Stop();
         timer.Dispose();
         isSendRunning = false;
         sendSocket.Shutdown(SocketShutdown.Receive);
         sendSocket.Close();
         sendSocket = null;
     }
 }
Esempio n. 2
0
        public static void TryInitMMTimer()
        {
            try
            {
                mmTimer          = new MmTimer();
                mmTimer.Interval = 1;
                mmTimer.Tick    += (s, e) =>
                {
                    if (!UpdateByTimer)
                    {
                        UpdateByTimer = true;
                        waitStartEvent.Set();
                    }

                    DateTime now   = DateTime.Now;
                    long     ticks = now.Ticks - _Now.Ticks;
                    if (ticks < 0 && ticks > (-5L * MINITE * 10000))
                    {
                        return; //时间倒退是不允许的
                    }

                    if (CorrectTimeSecs != 0)
                    {
                        now = now.AddSeconds(CorrectTimeSecs);
                    }

                    _Now = now;
                    Thread.VolatileWrite(ref CurrentTicks, now.Ticks / 10000);
                };
                mmTimer.Disposed += (s, e) =>
                {
                    UpdateByTimer = false;
                    if (null != mmTimer)
                    {
                        mmTimer.Stop();
                        mmTimer = null;
                    }
                };

                mmTimer.Start();
                //WaitStart();
            }
            catch (System.Exception ex)
            {
                UpdateByTimer = false;
            }
        }
        /// <summary>
        /// Stop cyclic processes of the communication, set devices to init,
        /// close socket and set Connected to false
        /// </summary>
        public override async void Disconnect()
        {
            try
            {
                timerUpdatePdoProperties.Enabled = false;

                for (int i = 0; i < Devices.Count; i++) //
                {
                    if (Devices[i] is PCS device)
                    {
                        device.timerNonRealTime.Enabled = false;
                    }
                }

                ts_scope.Cancel();

                if (MmTimer.IsRunning)
                {
                    MmTimer.Stop();
                }

                await Task.Delay(25);

                await Task.Run(() =>
                {
                    try
                    {
                        EcSmRequestStateAll(EC_SM.EC_STATE_INIT);
                        EcCloseSocket();
                    }
                    catch (Exception err)
                    {
                        MessageBox.Show(err.ToString());
                    }
                });

                Connected = false;
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString());
            }
        }
Esempio n. 4
0
 public void Stop() => _timer.Stop();
Esempio n. 5
0
 public void EvtStop()
 {
     _telemetryUpdater.Stop();
 }
Esempio n. 6
0
 public void Close()
 {
     can.Close();
     timer.Stop();
 }