标题:小白系统定时器使用没有反应,求助
只看楼主
Edwardyao
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2020-7-28
 问题点数:0 回复次数:0 
小白系统定时器使用没有反应,求助
namespace 图形闪烁调试
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        bool picAidThreadMark = true;
        System.Timers.Timer timer1 = new System.Timers.Timer();
        int picId = 0;
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            timer1.Enabled = true;
            timer1.Interval = 2000;
            while (picAidThreadMark)
            {
                if (picId == 0)
                {
                    pictureBox1.ImageLocation = @"E:\sleepHelp\图形闪烁调试\图形闪烁调试\bin\Debug\QQ.ico";
                }
                else pictureBox1.ImageLocation = null;
                timer1.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Tick);//到时间的时候执行事件;
            }
            //pictureBox1.ImageLocation = @"E:\sleepHelp\图形闪烁调试\图形闪烁调试\bin\Debug\QQ.ico";
        }
         void timer1_Tick(object sender, EventArgs e)
        {
            this.Invoke(new Action(() =>
            {
                picId += 1;
                picId = picId % 2;
            }));
        }
    }
}
//就是想实现图片闪烁,这段代码怎么会没有反应呢,且线程数一直增加,invoke里每次就整数赋值,赋值完成了这个线程不就应该停止了吗?求助
搜索更多相关主题的帖子: 闪烁 System new 图形 调试 
2020-07-28 20:19



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-502660-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.182178 second(s), 7 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved