是不是要把刷新窗口操作放到UI线程里   我要怎么得到这个UI线程呢

解决方案 »

  1.   

    this.Invoke(new MyThisDelegate(this.GetThisDate)); 
    还有这句话出现异常
    未将对象引用设置到对象的实例。
    这个是什么原因啊
      

  2.   

    this.GetThisDate这个是不是null?
    this是不是null?
    GetThisDate需不需要参数?
    GetThisDate里面会不会出来null?反正一句话,就是你调用了某个为null的对象的成员。
      

  3.   

    public  delegate  void  MyThisDelegate();
    MyThisDelegate 这个没用参数
    GetThisDate 就是绑定2个datagrid控件
      

  4.   

    用这语句this.Invoke(new MyThisDelegate(this.GetThisDate)); 绑定datagrid控件时界面会假死程序有2个辅助线程分别为2个全局变量添加数据,然后使用this.Invoke(new MyThisDelegate(this.GetThisDate)); 为datagrid控件绑定数据,过一会界面就死拉,会不会时ui线程和辅助线程同时访问全局变量得原因啊   要怎么解决 
      

  5.   

    "会不会时ui线程和辅助线程同时访问全局变量得原因"?
    根据你的描述,应该不会,因为界面线程只是读数据。你不是说会出异常吗?怎么又变成假死了?你在this.GetThisDate里面设断点跟踪一下先......
      

  6.   

    “EmailMonitor.exe”: 已加载“c:\windows\assembly\gac\mscorlib.resources\1.0.5000.0_zh-chs_b77a5c561934e089\mscorlib.resources.dll”,未加载符号。
    未处理的“System.NullReferenceException”类型的异常出现在 system.windows.forms.dll 中。其他信息: 未将对象引用设置到对象的实例。
    未处理的异常: 线程 '<无名称>' (0xf18) 已退出,返回值为 0 (0x0)。
    System.NullReferenceException: 未将对象引用设置到对象的实例。
       at System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG& msg, HandleRef hwnd, Int32 msgMin, Int32 msgMax, Int32 remove)
       at System.Windows.Forms.ComponentManager.System.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at EmailMonitor.Form1.Main() in d:\程序备份\fax\emailmonitor\monitor.cs:line 337程序“[2424] EmailMonitor.exe”已退出,返回值为 0 (0x0)。/// <summary>
    /// 应用程序的主入口点。
    /// </summary>
    [STAThread]
    static void Main() 
    {
    Application.Run(new Form1());}//在这报的个异常这个异常是什么意思啊  要怎么找到报异常的地方啊
      

  7.   

    参看
    http://blog.csdn.net/knight94/archive/2006/03/16/626584.aspx
    http://blog.csdn.net/Knight94/archive/2006/05/27/757351.aspx
      

  8.   

    能不能执行到GetThisDate方法里?设个断点调试跟踪一下
      

  9.   

    private void GetThisDate()
    {
    dataGrid1.DataSource = dt;
    dataGrid2.DataSource = dtState;

    }
    dt,dtState为2个全局变量
    有2个线程分别为这2个全局变量添加数据,ui线程读数据时正好辅助线程正好往里添加数据,怎样会出现什么问题吗(除了数据不同步外)
    设个断点调试跟踪可以进入里面,其后界面就死拉
      

  10.   

    楼主,在Invoke函数中缺少参数
    应该改为this.Invoke(new MyThisDelegate(this.GetThisDate),new object[]{null,null})
    这样应该就没有错误了
      

  11.   

    to:crystalreport20xx(自学者)
    GetThisDate这个方法没有参数  也改成this.Invoke(new MyThisDelegate(this.GetThisDate),new object[]{null,null})吗??
    to:一句一句的执行,看到底是哪句出的错,还是这个函数能执行完?
    先可以进去 一句一句的执行都没错误,其后界面就死拉 在进不去拉
      

  12.   

    最好你使用线程间的通信,来协调UI和worker线程
    看看吧http://blog.cnbie.com/blog_8698.html