• 车辆信息统计报表管理系统子、父线程调用的问题(委托)


            下面这个委托有问题,死循环会导致CPU 100%。子线程不能调用父线程。

            while (!this.WinControl.IsHandleCreated)

            {

     

            }

            this.WinControl.Invoke(dalegateBinding);//调用委托去刷新窗体

         

           修改后的:

     #region使用线程绑定数据

     

            Thread ThreadBinding = null;

            ThreadStart BindingStart = null;

     

            delegate void BindingHander();

            BindingHander dalegateBinding = null;

            ///<summary>

            ///线程加载数据

            ///</summary>

            private void BindingData()

            {

                BindingStart = new ThreadStart(GetBindingData);

                ThreadBinding = new Thread(BindingStart);

                ThreadBinding.IsBackground = true;

                ThreadBinding.Name = "EngineRotateSpeed_Analysis_Widget";

                ThreadBinding.Start();

                dalegateBinding = new BindingHander(DoBindingData);

            }

     

     

            DataSet ds = new DataSet();

            WidgetDrive mWidgetDrive = new WidgetDrive();

     

            ///<summary>

            ///获取数据与绑定

            ///</summary>

            void GetBindingData()

            {

                try

                {

                    ds = DataLayerTest.Get_Engine_RotateSpeed_Analysis_List_Rpt(mWidgetDrive);//获取数据

                   if (this.WinControl==null||this.WinControl.IsDisposed)

                    {

                       

                    }

                    else

                    {

                            while (!Helper.CanUse(this.WinControl))

                            {

     

                            }

     

                            this.WinControl.Invoke(dalegateBinding);//调用委托去刷新窗体

                    }

                }

     

                finally

                {

                    ThreadBinding.Abort();

                }

            }

     

            ///<summary>

            ///用获取的DataSet分运行时间端绑定器件数据

            ///</summary>

            void DoBindingData()

            {

                ZedGraphControl zgc = base.WinControl as ZedGraphControl;

                switch (mWidgetDrive.ChartType)

                {

                    case TimeType.Day:

     

                        CreateChartDay(ref zgc);//生成日图表

     

                        break;

                    case TimeType.Week:

     

                        CreateChartWeek(ref zgc);//生成周图表。

     

                        break;

                    case TimeType.Month:

     

                        CreateChartMonth(ref zgc);//生成月图表。

     

                        break;

                }

                zgc.Invalidate();

            }

            #endregion

              // Helper类里面的CanUsr方法

    internal static bool CanUse(Control control)

    {

        return control!=null&&!control.IsDisposed && control.IsHandleCreated;

     }

     

  • 相关阅读:
    idea中运行hadoop的案例使用打jar包的方式操作(HDFS java API)
    eclipse集成使用Hadoop插件运行WordCount程序
    Linux中hadoop运行第一个自带的Wordount程序
    windows配置hadoop环境变量
    Linxu安装mysql
    Linux开机自启动网路连接
    studio开发之简单的登陆
    使用JDK自带的JConsole性能调优
    观察者模式
    mysql中的(B+数据)
  • 原文地址:https://www.cnblogs.com/Gemgin/p/3136355.html
Copyright © 2020-2023  润新知