コード例 #1
0
        private void PollCustomCommand()
        {
            CultureInfoHelper.SetDateTimeFormat();
            while (!_cts.IsCancellationRequested)
            {
                try
                {
                    var now = DateTime.Now;
                    var customCommandList = DasConfig.Repo.GetLastCustomCommand(now);

                    if (customCommandList == null || !customCommandList.Any())
                    {
                        Thread.Sleep(1000);
                        continue; //没有命令
                    }
                    foreach (var item in customCommandList)
                    {
                        // 接触命令, 准备执行.
                        item.Accept();
                        Task.Factory.StartNew(() => HandleCustomCommand(item));
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Thread.Sleep(10 * 1000);
                    // 保证线程持续进行
                }
                Thread.Sleep(1000);
            }
        }
コード例 #2
0
        public void Start()
        {
            Task.Factory.StartNew(() =>
            {
                CultureInfoHelper.SetDateTimeFormat();
                while (!_cts.IsCancellationRequested)
                {
                    // das 循环发送命令, 并接受报文.
                    try
                    {
                        //if (Comm == null || !Comm.IsConnect)
                        //{
                        //    Log($"网络断开,{Comm}重新连接.");
                        //    Comm?.Start();
                        //    Thread.Sleep(3000);
                        //    continue;
                        //}
                        GatherData();

                    }
                    catch (Exception e)
                    {
                        LogD.Error("轮询中出现错误:" + e);
                    }
                    finally
                    {
                        Thread.Sleep(50);
                    }
                }

            }, _cts.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
コード例 #3
0
 //private Thread _loadThread;
 public BasePlugin()
 {
     CultureInfoHelper.SetDateTimeFormat();
     LogDogCollar    = new LogDogCollar();
     LogDogRoot      = RegisterLogDog(Title);
     BaseDirectory   = Path.GetDirectoryName(Assembly.GetAssembly(this.GetType()).Location);
     _pluginMonitors = InitMonitors();
     _pluginKVs      = InitKvs();
 }