Reputation: 195
I have an application (vb.net version 4.0).When launching an command from the application, windows forms will pop-up saying "please wait till operation ends". Even If I minimize the whole application and goes to word application.This pop-up is not minimized.
the second issue is, there are multiple commands in this application. Each command will launch a windows form. If an windows form is already launched, another commands shouldn't getting hit. how to achieve this? Tried this:
Form.ShowDialog()
Form1.Activate()
Form1.BringToFront()
Form1.TopMost = True
New to vb.net. Help is highly appreciated
Upvotes: 0
Views: 37
Reputation: 74605
For your first problem, it sounds like you're doing some long operation using the thread that draws the UI, preventing it from doings it's job of updating the user interface. When this happens, Windows OS will show a message if it detects the operation is unresponsive.
The way windows works internally is it has a queue for your application that it posts messages into for things like window drawing command, mousebutton clicks and keypresses etc. The main thread that started your app has the job of consuming that queue and keeping it small. If you do something (let's say you start calculating Pi to 3 quadrillion places) in a button Click event handler then the main thread no longer has the ability to consume the messages out of the windows queue. Windows notices the queue growing longer and longer and shows the "this application is not responding" message.
You can only avoid this by NOT doing long operations on the windows thread, or by using some sort of asynchronous/multithreading to do your long operation, which will let the main thread go back to its job of consuming the windows message queue
For your second query, it seems reasonable:
When you use ShowDialog()
execution of that code will pause at the point ShowDialog is called and only carry on when the form that was opened with ShowDialog() is closed
ShowDialog is intended for asking the user a question where you need the answer in the lines of code after. If the code didn't pause while the dialog was open the user wouldn't have time to give the answer before the code needed the answer
In your code there, until Form
is closed, Form1.Activate()
will not happen. As soon as Form is closed, the remaining 3 statements will be called
Note that if Form starts a long running operation then it too will cause the "application not responding" problem
Upvotes: 1