Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 线程中的用户界面访问_Vb.net_Multithreading_User Interface - Fatal编程技术网

Vb.net 线程中的用户界面访问

Vb.net 线程中的用户界面访问,vb.net,multithreading,user-interface,Vb.net,Multithreading,User Interface,在我的应用程序中,我有grid和picturebox。我想在加载网格和一些进程时显示图片框。我正在这样尝试 Dim mRestoreThread as thread 在LoadDataGrid调用之前,设置PictureBox1.Visible=true mRestoreThread = New Thread(AddressOf LoadDataGrid) mRestoreThread.IsBackground = True mRestoreThread.Start() 此方法

在我的应用程序中,我有
grid
picturebox
。我想在加载网格和一些进程时显示图片框。我正在这样尝试

Dim mRestoreThread as thread 
在LoadDataGrid调用之前,设置
PictureBox1.Visible=true

  mRestoreThread = New Thread(AddressOf LoadDataGrid)
  mRestoreThread.IsBackground = True
  mRestoreThread.Start()
此方法完成后,设置
PictureBox1.Visible=false

(显示此图片框用于正在进行的处理)

如何做到这一点?有可行的解决方案吗?

试试这个

Private Sub LoadDataGrid()
    'do whatever here
    '
    '
    'at the end do
    Me.Invoke(New MethodInvoker(AddressOf hidePB))
End Sub

Private Sub hidePB()
    PictureBox1.Visible = False
End Sub

还有一些较短的方法。

您正在将picturebox设置为在启动线程所需的时间内可见-您没有在上面的代码中等待它发出它已完成的信号?@RowlandShaw如何从该线程获得它已完成的信号?您发布的代码是否正在UI上运行,我想是这样的?交叉线程错误发生在哪里(显示代码)?@dbasnett我找到了交叉线程错误并解决了它。在loaddatagrid函数中,我正在设置电流。您的问题已经解决了?感谢您宝贵的时间。但它不起作用。调用loaddatadrive时,picturebox不可见。设置PictureBox1.visible=true后,请尝试PictureBox1.Refresh。它正在写入。图片框可见。但有一个问题。在我的图片框中,我有一个动画图像,它没有动画。听起来像是另一个问题。问一个新问题,并张贴应该使其动画化的代码。