Dnx_7
asked on
How to open form in a new thread an montor it in the main form
hi experts,
all is in the title!
i have a mainform
i would like to launch a form from the main form in a new thread and monitor it
eg :
report status, thread status, exchange information between the main form and the form in the new thread
is it possible? if yes how?
regards
all is in the title!
i have a mainform
i would like to launch a form from the main form in a new thread and monitor it
eg :
report status, thread status, exchange information between the main form and the form in the new thread
is it possible? if yes how?
regards
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you were to launch a new thread, and in that first sub you declared a new form and set it to show... would that still run on the main thread?
I've made progress forms to show on seperate threads to keep track of work being done before, but I always just assumed it was working on the thread I had intended it to?
I've made progress forms to show on seperate threads to keep track of work being done before, but I always just assumed it was working on the thread I had intended it to?
ASKER
yes i'm using visual 2005
me.parentform need mdi form right? or i'm wrong?
i guess it is possible because i had made a "sample" but that is not working properly
i start a new thread and invoke a new form
then i add the process into an arraylist to keep track of the new form
then a timer will cast the arraylist to the form and then retrieve information
me.parentform need mdi form right? or i'm wrong?
i guess it is possible because i had made a "sample" but that is not working properly
i start a new thread and invoke a new form
then i add the process into an arraylist to keep track of the new form
then a timer will cast the arraylist to the form and then retrieve information
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Do everything from the main UI thread. To "create" the form in a different thread you would need to use Delegates and Invoke() to marshal the call from your thread to the main UI thread where it is safe to create controls/forms...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
riyazthad,
Using your code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As New System.Threading.Thread(Ad dressOf CallMe)
t.Start()
End Sub
Private Sub CallMe()
Dim f As New Form2
System.Windows.Forms.Appli cation.Run (f)
End Sub
End Class
Click the button to open up Form2. Now close Form2...then close Form1. The app gets stuck and doesn't exit completely...
Can you explain or fix that?
Using your code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim t As New System.Threading.Thread(Ad
t.Start()
End Sub
Private Sub CallMe()
Dim f As New Form2
System.Windows.Forms.Appli
End Sub
End Class
Click the button to open up Form2. Now close Form2...then close Form1. The app gets stuck and doesn't exit completely...
Can you explain or fix that?
Did you add any other code or anything doing in close event?
That peice of code is working fine in my end.
Thad
That peice of code is working fine in my end.
Thad
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Yes in 2003, you can do it. It wont make any issues. If you are using VS 2005, it is good to call using delegate and Invoke.
Right...2003 doesn't throw an error. Cross thread communication without Delegates and Invoke() is a bad practice...
Just as long as the author is aware of that. =)
Just as long as the author is aware of that. =)
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hi, i'm aware about the cross invalid thread and i have to make this property to true
that's why i'm asking people experts here to help me to create form form the main ui form in safe thread...
regards
that's why i'm asking people experts here to help me to create form form the main ui form in safe thread...
regards
The second form will run on the main forms thread.