Modal form from a thread

G

Guest

I was wondering if anybody had any suggestions on the following requirement

I have an MDI parent form with a child form. A seperate thread is created by the child form to run a computation. The progress of the computation should be reported to the user, and also allow the user to cancel at any time. The form that displays the progress should be modal to prevent access to the MDI parent until the computation is complete. There are several different types of computations that can be run so the form that displays the progress shouldn't implement the code. What is the best approach to handling this situation

On the computation thread I have tried invoking the modal display of the progress form on the child form and using a delegate to transfer control back to the computation thread. This works but the progress form isn't modal (it is always on top though). I can still access the MDI parent.
 
B

Bill McCarthy

Hi Peter,

I am unclear as to why you are using another thread, if the requirement is that
the computation actually be blocking. Why not just show a form modally, and
have that form initiate the computation and receive progress events ?

Bill.



Peter said:
I was wondering if anybody had any suggestions on the following requirement.

I have an MDI parent form with a child form. A seperate thread is created by
the child form to run a computation. The progress of the computation should be
reported to the user, and also allow the user to cancel at any time. The form
that displays the progress should be modal to prevent access to the MDI parent
until the computation is complete. There are several different types of
computations that can be run so the form that displays the progress shouldn't
implement the code. What is the best approach to handling this situation?
On the computation thread I have tried invoking the modal display of the
progress form on the child form and using a delegate to transfer control back to
the computation thread. This works but the progress form isn't modal (it is
always on top though). I can still access the MDI parent.
 
H

Herfried K. Wagner [MVP]

* "=?Utf-8?B?UGV0ZXI=?= said:
I have an MDI parent form with a child form. A seperate thread is
created by the child form to run a computation. The progress of the
computation should be reported to the user, and also allow the user to
cancel at any time. The form that displays the progress should be modal
to prevent access to the MDI parent until the computation is complete.
There are several different types of computations that can be run so the
form that displays the progress shouldn't implement the code.

Progress Dialog (for C#, can be converted to VB.NET):

<URL:http://www.codeproject.com/cs/miscctrl/progressdialog.asp>

Multithreading + Windows Forms:

<URL:http://www.devx.com/dotnet/Article/11358/>
 
G

Guest

Herfried

Thank you so much, that lead me to another article which explained it very well. I can reproduce it in my code and it works well.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top