I've a main form and upon pressing of a button, wanted to create a new form in another thread.
However, when the new form is launched in the new thread, it seems that it simply disappear thereafter.
This happens even if the thread is being keep tracked (thread not being disposed).
Give it a try and let me know if you have any idea on a solution to it.
Thanks.
regards,
choongseng
You can try the codes below:
Private Sub btnForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnForm.Click LaunchForm() End Sub Private Sub btnThreadForm_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnThreadForm.Click Dim th As New Threading.Thread(AddressOf LaunchForm) th.Start() End Sub Private Sub LaunchForm() Dim frm As New frmThreadDemo frm.Show() End Sub
Consider the life span of your thread - LaunchForm() is only two lines for the new thread to execute. What happens after that? It terminates; nothing else to do.
Since that thread is the owner of the new form (having created it), it disappears along with the thread.
Typically there is only one UI thread that renders all the UI elements. Additional threads are worker threads that do work not pertaining to drawing the UI. If you really want another thread to handle UI-rendering chores of new windows, you must then keep that thread "busy" so it does not terminate.
The melody of logic will always play out the truth. ~ Narumi Ayumu, Spiral