.Net monkeys - Help needed!

Soldato
Joined
5 Mar 2003
Posts
10,768
Location
Nottingham
Hello there!
Basically I have a MDI program and I need to freeze one of the windows, but allow access to other windows.
i.e. they open up two different windows within my program. In the one window they press a button which pops up a box with a progress bar and peforms a task. While this task is going on I dont want them to be able to click on the window that popped the box up.
However, should they click on the second window that isnt doing anything, this is acceptable! So for the first window, i need basically "do modal" functionality.... but when ever i do that it stops the user where ever they click on the main MDI program.

Any ideas? :x
 
Off the top of my head, sounds like the forms need to be in separate threads. That's all well and good if you wrote the MDI interface but if you're using the standard MDI it might be harder, not tried it.

If one is performing a task while user input can still be accepted from the other, sounds like multi-threading would be a good idea anyway.
 
i'm not sure on this, but it's possible there's some way of 'disabling' the form while you're working on it :S i might be best looking on the msdn knowledge base or finding a decent .net forum. sorry i can't be more help.
 
myForm.Enabled = false;

You'll either have to launch one form from the other and keep a ref to it or launch them both from some controller class and keep a ref to each in that.

As said above, if you want to continue accepting input while a calculation is going on in the background you'll have to run the calculation in a thread or it will lock up the whole program. You might want to look up threadsafe forms applications if you want to avoid any possible synchro issues (you'll probably want to pass the task/progress window a delegate that can be used to call back to the main window to say "I'm finished" or whatever...)
 
Oh, also, if you use myForm.ShowDialog() on the progress window rather than Show() it will halt execution on the calling thread until it is closed. This would probably be the best way of isolating one form because it also prevents you focusing it (makes the borders flash and makes a *bloonk* noise if you try).

You'll still have to run the process in a thread though...
 
showdialog isnt an option as it means the one window has to be closed before the other gets focus again.
The calculation will defo go in a seperate thread, thats not a problem.
I will look into the methods give.... just thought (read: hoped) that there was an ultra easy way i was missing :P
 
Don't we have three forms here? Two main windows and one "progress" dialog? I thought you wanted one form to launch the dialog and block until it has finished. If you open both by whatever means you want and then use showdialog from inside one of them to launch the third only that one window will block and only the dialog will close when it has finished.

Is that not what you want to do?
 
There is one program which has two "child" windows open within it.
When one child window is busy doing something, the other window should still be active / interactable.
The "busy" child window has a dialog box saying busy / showing the status of the current operation, but should they click on the window, it should act like it has a modal dialog box (ie "beep" -> dialog box highlighted).

When I tried to do a "showdialog" from the child window is freezes the whole app -> reading up on this shows its due to the interface being all on one thread. I do not have the knowledge to code my own MDI application, so have to use the .Net default settings which seems to have a single thread for all GUI actives.

Hope this is clearer :)
 
Without knowing exactly what your app is doing, is it possible to consider implementing the progress indicator within the child window itself (perhaps on a status bar) rather than on a popup dialog? I think this is a common approach in other apps that support background processing in child windows, and might give you less "windowing" headaches ;)

cheers
v.f.
 
possibly - havent thought of that approach...
but i still need to freeze the window, else they could kick off two commands which is bad :S
I guess i could just disable the text box / button.... hmmmm
not exactly what i wanted, but if it does the job...

Thanks :)
 
If you want the progress bar to continue to run then you can't disable the form. You could disable all the controls on other than the PB, but even then unless you launch the form on a seperate thread from the MDI and the other form then it may not work reliably. Personally I'd just run the particular task on a seperate thread then on you UI thread use a timer to tick the PB and use some form of callback mechanism to notify the UI thread when the task is complete.

There's plenty of delegate examples showing how to do asynchronous worker ops out there so you should be able to crib it if your unfamaliar. There's even an MSDNTV bit that has a good example IIRC.
 
Back
Top Bottom