Click to See Complete Forum and Search --> : ShowDialogue
vivienlwt
September 15th, 2010, 09:53 AM
Here's the relation among the 3 forms:
Form A calls Form B which is independent of it (I use Show() here).
Then Form A calls Form C which is obliged to do some operations before returning back to Form A(I use ShowDialogue() here).
But here's the problem, form C also takes up the focus of form B, so B is not independent of C. Is there anyway that B could be active when C is open? I want to do some operations on B while C is open.
Many thanks.
Arjay
September 15th, 2010, 04:35 PM
The only way to do it is to open C with Show( ).
The reason is that there can only be one active modal form per application at a time.
If you open C with ShowDialog( ) it will be modal and prevent you from accessing B until you close C.
vivienlwt
September 16th, 2010, 02:38 AM
ok, so this means that i have to handle the relation between A and C myself. I mean A should 'sleep' till C is closed. But to let B still be accessible while A is waiting for the answer of C, do I have to make B be another thread apart from the main thread?
thank you
vivienlwt
September 16th, 2010, 03:29 AM
Or instead, can I create a new thread to take care of B, then A calls C as a modal form. Then will B be accessible when C is open?
Arjay
September 16th, 2010, 11:08 AM
Don't use threads - you'll want to keep all of the UI in the same thread.
You can't 'sleep' A either. If you do, you'll block B & C too.
What you can do is to disable the controls in A before opening C and reenable them when C closes.
vivienlwt
September 17th, 2010, 06:57 AM
thank you!! but it's not as easy as disable the controls. A is waiting for the data from C to resume some calculation. if using one thread, I cannot put a while loop to wait, otherwise it will block the whole process. so in the end what i did is to create a thread to run form B and use delegate to invoke some functions from time to time. luckily the operations on B is not very complex.
Arjay
September 17th, 2010, 12:25 PM
thank you!! but it's not as easy as disable the controls. A is waiting for the data from C to resume some calculation. if using one thread, I cannot put a while loop to wait, otherwise it will block the whole process. so in the end what i did is to create a thread to run form B and use delegate to invoke some functions from time to time. luckily the operations on B is not very complex.You misunderstand about threading. In threading, you put the worker operations in the threads, not the UI. Your mistake is running form B from the worker thread. Keep Form B in the main UI thread and use delegates to update the UI components (in the UI thread).
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.