zoukankan      html  css  js  c++  java
  • C#的计时器执行中的多线程问题

    c#中有两个计时器,一个在FORM使名空间,一个在System命名空间。

    一般前者在window form 应用中使用,后者在window service,后台管理中使用。

    常见问题之一:计时器执行时间比间隔要大时出现多线程问题。

      private void timer1_Tick(object sender, EventArgs e)
      {

               lock(o)
                {
                    try
                    {
                        if (GrobalManage.gmstepindex < GrobalManage.gmstepcount - 1)
                        {
                            GrobalManage.gmstepindex++;
                            if (MeshSetting.isContourShow && MeshSetting.variable_index != 0)
                            {
                                GrobalManage.IGetCurrentStepData(MeshSetting.variable_index - 1, GrobalManage.gmstepindex);
                            }
                            ComboBox_timeStep.SelectedIndex = GrobalManage.gmstepindex;
                            MyMapView.tick();    //这个函数执行时间比计时器间隔要大。                    
                            ProgressBar.Maximum = GrobalManage.gmstepcount - 1;
                            ProgressBar.Value = GrobalManage.gmstepindex;
                        }
                        else
                        {
                            timer1.Enabled = false;
                        }
                    }
                    catch (Exception err)
                    {
                        timer1.Enabled = false;
                    }
                }
            }
    如上运行后还是出现多线程问题,在MyMapView.tick()这个函数内增加线程控制后问题解决。

  • 相关阅读:
    Jquery 下实现 图片大图预览效果
    PHP之图片上传类(加了缩略图)
    无限极分类
    inno steup 安装判断 进程是否运行
    mac os 10.15安装jdk 1.6
    c# 创建delphi的代码
    php 断点续传以及100% 后台zip解压
    多个编号重复,递归处理
    php映射echarts柱状图
    php数据映射到echarts中国地图
  • 原文地址:https://www.cnblogs.com/wangrsh2010/p/2088619.html
Copyright © 2011-2022 走看看