0

I'm extremely novice at threading and I'm simply creating a single thread to run a large function. I've created a messagebox to appear at the end of the function towards the end of the program to tell me the load time it took. As i load the application, the messagebox will appear with a time it took and THEN the thread will kick off(although the UI is navigable while the components are loading from the thread) isn't the point of threading to be able to process multiple functions at the same time? Why is this waiting until the main thread is finished before the new thread kicks off?

I declare and start the new thread early in the app

4

2 回答 2

2

对于应用程序命名空间中的每个 Form,将在 Forms 属性下的 My 命名空间中创建一个默认实例。

---------------------- / 启动主线程 / ----------- ------------

Private Sub FindCustomerLocation()
Dim Findcontractor_Thread As New Thread(AddressOf **FindContractor_ThreadExecute**)
Findcontractor_Thread.Priority = ThreadPriority.AboveNormal
Findcontractor_Thread.Start(**me**)
End Sub

------------------ / 运行线程 / ---------------

Private Sub **FindContractor_ThreadExecute**(beginform as *NameOfFormComingFrom*)
Dim threadControls(1) As Object
threadControls(0) = Me.XamDataGrid1
threadControls(1) = Me.WebBrowserMap

 **FindContractor_WorkingThread**(threadControls,beginform) ' ANY UI Calls back to the Main     UI Thread MUST be delegated and Invoked

End Sub

------------------ / 如何从线程设置 UI 调用 / ------------------

Delegate Sub **FindContractor_WorkingThread**(s As Integer,beginform as           *NameOfFormComingFrom*)
Sub **FindContractor_WorkingThreadInvoke**(ByVal s As Integer,beginform as     *NameOfFormComingFrom*)
If beginform.mouse.InvokeRequired Then
Dim d As New FindContractor_WorkingThread(AddressOf            FindContractor_WorkingThreadInvoke)
beginform.Invoke(d, New Object() {s,beginform})
Else
 beginform.Mouse.OverrideCursor = Cursors.Wait

    'Do something...

beginform.Mouse.OverrideCursor = Nothing
 End If
End Sub

来自 Pakks 的消息来源回答并经过测试!

于 2013-07-25T20:33:32.377 回答
1

如果您希望它们按照您的想法(同时)运行,则必须创建多个线程。查看此链接并尝试创建多个线程。这应该可以帮助您解决问题。干杯

http://msdn.microsoft.com/en-us/library/ck8bc5c6%28v=vs.80%29.aspx

于 2013-07-24T16:52:54.580 回答