Esempio n. 1
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            Console.WriteLine("Application is running....");

            var j = new NJob();

            j.Run += (a, b) =>
            {
                string jobName     = b.Name;
                bool   paramResult = int.TryParse(b.RunParam, out int lowerBound);
                if (!paramResult)
                {
                    lowerBound = 99999;
                }
                _monitorService.RunMonitor(lowerBound, jobName).Wait();
            };


            j.Error += (a, b) =>
            {
                Console.WriteLine("{0} {1} ERROR:{2}", DateTime.Now, b.Def, b.Exception.Message);
            };

            j.Start();

            return(Task.CompletedTask);
            //j.Stop();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string aaa = null;

            Console.WriteLine(aaa.IsNullOrEmpty());

            var r = new NJob();

            r.Run += (a, b) => {
                string logObj           = b.Name;
                System.Net.WebClient wc = new System.Net.WebClient();
                wc.Encoding = Encoding.UTF8;
                string ret = wc.DownloadString(b.RunParam);
                ret = string.Format("{0} {1} 第{3}次执行结果:{2}", Now, logObj, ret, b.RunTimes);

                Console.WriteLine(ret);
                Console.Write(DateTime.Now);
            };


            r.Error += (a, b) => {
                //b.Def.RunParam
                Console.WriteLine("{0} {1} 发生错误:", Now, b.Def, b.Exception.Message);
            };

            r.Start();

            Console.WriteLine("...");
            Console.ReadKey();
            r.Stop();
        }