【发布时间】:2015-08-14 02:24:54
【问题描述】:
在我的主窗体中,我有一个按钮可以跨多个数据库加载大量存储过程。我想在加载时创建一个进度/等待表单。当我按下按钮时,它会显示等待表单。
我有一个调用workerDoWork 的后台工作进程。
在该方法中,我想调用具有所有代码的主窗体来进行加载。当我公开它时,我可以调用它。但是主窗体内有很多引用,全局变量,被调用的不同方法都不起作用。我怎样才能让它工作而不必将所有代码移动到等待表单中。?
等待表单中的代码。
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
_worker = New BackgroundWorker()
AddHandler _worker.DoWork, AddressOf WorkerDoWork
AddHandler _worker.RunWorkerCompleted, AddressOf WorkerCompleted
_worker.RunWorkerAsync()
End Sub
' This is executed on a worker thread and will not make the dialog unresponsive. If you want
' to interact with the dialog (like changing a progress bar or label), you need to use the
' worker's ReportProgress() method (see documentation for details)
Private Sub WorkerDoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
'Dim main As New frmMain()
frmMain.LoadARData()
' MsgBox("hi there ")
End Sub
' This is executed on the UI thread after the work is complete. It's a good place to either
' close the dialog or indicate that the initialization is complete. It's safe to work with
' controls from this event.
Private Sub WorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
Me.DialogResult = Windows.Forms.DialogResult.OK
Me.Close()
End Sub
【问题讨论】:
-
请向我们展示您的代码,否则我们无法为您提供帮助!
-
它以什么方式“不起作用”?
-
好吧,我发现它很奇怪..如果我从主窗体运行方法,我将一个日期变量传递给我的存储过程。 dtpAgeDte.Text 在加载时自动设置。但是如果我从等待表单中调用该方法..它会爆炸并说不能将字符串“”转换为日期..就像它没有拿起日期
-
如果您使用 BGWm 进行处理,为什么还需要等待表单?
-
我只有一个显示“等待”的表单,一个向用户显示它正在加载的加载表单......这就是重点