Lengthy operation without blocking the UI
-
Hi, I need to call into a library to perform a lengthy operation after a user presses a button. I would like to bring up a dialog asking the user to wait a moment (no buttons on this dialog). In the background I would like the operation to be performed. When it is ready, the dialog should be destroyed. Has anyone done anything similar to this? Could someone point me to a sample or give me a few tips? I am using MFC. thanks, Jeremy Pullicino C++ Developer Homepage
-
Hi, I need to call into a library to perform a lengthy operation after a user presses a button. I would like to bring up a dialog asking the user to wait a moment (no buttons on this dialog). In the background I would like the operation to be performed. When it is ready, the dialog should be destroyed. Has anyone done anything similar to this? Could someone point me to a sample or give me a few tips? I am using MFC. thanks, Jeremy Pullicino C++ Developer Homepage
This sounds like a job for a background worker thread. There are two methods I use to unblock a lengthy operation: 1. pumping the message queue intermittently (in VB, this was known as DoEvents) 2. Threads. (worker or UI, depending on the usage). you should be able call your function via a worker thread, using an event to signal when the process is finished and therefore when to destroy your status dialog. Have a look at: http://users.stargate.net/~newcomer/workerthreads.htm[^], where there is an excellent article on thread usage. **I Dream of Absolute Zero
**
-
Hi, I need to call into a library to perform a lengthy operation after a user presses a button. I would like to bring up a dialog asking the user to wait a moment (no buttons on this dialog). In the background I would like the operation to be performed. When it is ready, the dialog should be destroyed. Has anyone done anything similar to this? Could someone point me to a sample or give me a few tips? I am using MFC. thanks, Jeremy Pullicino C++ Developer Homepage
Well if you want to avoid the complexity of threads in C++, just put up a modeless dialog before you start your lengthy operation. Whether it has buttons on it like a "Cancel Lenghty Operation" button is up to you - having a button like this is actually harder, because you need to be able to interrupt the operation ( you would need to set a boolean and test that boolean as often as possible inside the lengthy operation). Anyhow what you described is easier - when the operation is finished, send a meessage to your modeless window to tell it to close down!