winfrom

cityem 2016-05-05 10:23:28
winfrom随机10-30分钟自动触发事件。
...全文
140 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
timer事件里修改间隔就行了,能有多复杂?
我是飞云 2016-05-05
  • 打赏
  • 举报
回复
    class Program
    {
        private static System.Timers.Timer aTimer;
        static void Main(string[] args)
        {
            Random r = new Random();//初始化方法1
            aTimer = new System.Timers.Timer();
            aTimer.Elapsed += TheOut;
            aTimer.Interval = r.Next(1, 5) * 1000;
            aTimer.AutoReset = false;
            aTimer.Enabled = true;

            TheOut(null, null);//初始化方法2
            Console.ReadLine();
        }

        public static void TheOut(object source, System.Timers.ElapsedEventArgs e)
        {
            aTimer?.Dispose();
            Random r=new Random();
            aTimer = new System.Timers.Timer();
            aTimer.Elapsed += TheOut;
            aTimer.Interval = r.Next(1, 5) * 1000;
            aTimer.AutoReset = false;
            aTimer.Enabled = true;
            Console.WriteLine("进来了,间隔:" + aTimer.Interval + "(ms)");
        }
    }

1,977

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧