当时钟事件声明为过程变量 让system.threading.timer时钟失效
2016-06-22 11:08
344 查看
这个项目的小模块就是画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 。世上好人多。红包发起。
中间用到了时钟,事件(带返回值的),哈希表 。由于时钟定义在 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 。世上好人多。红包发起。
相关文章推荐
- MyEclipse快捷键大全
- 【最短系列】C++ namespace
- 用JAVA实现网络数据包嗅探
- 在Beyond Compare中同步压缩文件夹的方法
- Javascript闭包与函数柯里化浅析
- 自定义控件—仿IOS7适用于Android的滑动开关
- 【BitMail】A Peer-to-Peer Instant Messenger Client
- Javascript :事件
- opencv下关于debug和release的切换报错问题
- 在AX中获得电脑屏幕的宽度和高度
- Python从入门到PY交易,基础语法,散记(二)
- 【5】用两个栈实现队列
- Readonly和Disabled的区别
- leetcode07- Reverse Integer之Java版本
- Android ImageView的属性android:scaleType
- Linux下文件的Access time,Modify time, Change time三个时间的概念、区别和联系。
- IntelliJ IDEA 导入已有Maven工程无法自动下载pom.xml内jar包
- datatables 小试牛刀
- jQuery基础修炼圣典—动画篇
- 【Python学习日记】dic和set 以及什么是 不可变对象