zoukankan      html  css  js  c++  java
  • 当时钟事件声明为过程变量 让system.threading.timer时钟失效

      这个项目的小模块就是画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 。世上好人多。红包发起。

  • 相关阅读:
    jar 反编译工具
    SpringBoot 中注解方式的拦截过滤
    jetty 启动项目在pom.xml 的配置
    java Exception 处理汇总
    mysql-覆盖索引
    程序员为何如此累
    启动centos 不带桌面
    Linux 和 Vim 常用命令整理
    How to Use tomcat on Linux
    Mac Book 问题汇集
  • 原文地址:https://www.cnblogs.com/zuochanzi/p/5606412.html
Copyright © 2011-2022 走看看