码迷,mamicode.com
首页 > 其他好文 > 详细

当时钟事件声明为过程变量 让system.threading.timer时钟失效

时间:2016-06-22 12:34:58      阅读:94      评论:0      收藏:0      [点我收藏+]

标签:

  这个项目的小模块就是画label 控件到tablepayoutpanel表单 之中, 

中间用到了时钟,事件(带返回值的),哈希表 。由于时钟定义在 form1的启动构造函数中导致了form1,启动完毕之后时钟停止运行,结果画label画到一半就停了,查找问题,甚是头大,后经大神帮忙,发现了过程变量的问题,在此总结。主要看红字标出部分

public Form1()
{
InitializeComponent();

//声明启动绑定事件
// OneCodeEventClass edt = new OneCodeEventClass();
OneCodeEvent += new OneCodeHander(MainPanel_Paint);
System.Threading.Timer timer = new System.Threading.Timer(new TimerCallback(OneCodeTest), null, 0, 100);

}

程序应该改为:

public partial class Form2 : Form
{
public System.Threading.Timer timer;  //添加了此行,在构造函数外声明全局变量
public Form2()
{
InitializeComponent();

//初始化颜色哈希表 1为未使用,0为使用,初始全部为1。
StartColorHashble();
//时钟 激活启动事件返回值字符串到MainPanel_Paint
OneCodeEvent += new OneCodeHander(MainPanel_Paint);
timer = new System.Threading.Timer(new TimerCallback(OneCodeTest), null, 0, 100);

PointXY.X = 0;
PointXY.Y = 0;
}

 

结果程序运行正常,在此谢谢帮我调试的大神carry 。世上好人多。红包发起。

当时钟事件声明为过程变量 让system.threading.timer时钟失效

标签:

原文地址:http://www.cnblogs.com/zuochanzi/p/5606412.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!