Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Sunday, December 28, 2014 5:34 AM
Hi, could someone direct me to a good reference for suspending a program temporarily for a few seconds while a message is displayed, say in a Text Box? The purpose is to display a “Program Complete” message for example for a short period within a module, then return to a main program that called the module. Thanks.
Michael Downing
All replies (9)
Tuesday, December 30, 2014 12:44 PM ✅Answered
Thanks all for the great suggestions; they led me to another solution which is most suitable for my application:
Threading.Thread.Sleep(10000)
This single line suspends the program for 10 seconds while I display any message desired in a form, then continue with normal program execution.
This concludes the thread.
Michael Downing
Monday, December 29, 2014 3:25 AM
Hi, could someone direct me to a good reference for suspending a program temporarily for a few seconds while a message is displayed, say in a Text Box? The purpose is to display a “Program Complete” message for example for a short period within a module, then return to a main program that called the module. Thanks.
Michael Downing
Hello,
To sum up, you just want to lock the main form to wait for the user closing that message, right?
It depends on how you call that module, and what that module is.
For the cases that module belongs to the same project and it doesn't contain UI.
1.If you called that module with a backgroundworker or another thread, then we could show that message with the following way.
TheControlOfThatMainForm.Invoke(Function() MsgBox("Your Message"))
That will execute that line with the UI thread, and when that message box appears, it will lock that form until the user close that message box.
2. If that is just a method, and you called it without any backgroundworker or another thread, then when it executing that line which displays message box, that should lock the UI until we close that message box.
Regards.
Carl
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.
Monday, December 29, 2014 3:52 AM
The purpose is to display a “Program Complete” message for example for a short period within a module, then return to a main program that called the module.
Add a timer to your form with a few seconds as the interval. Start the timer when you display the message. This is the last thing to execute in the method that completes the program.
In the timer tick event, close the form.
Whether or not this 'returns' to the main program depends on how that other form was opened. If it was opened using ShowDialog (rather than Show) then the code in the main form was suspended while the dialog was shown, and will continue when the dialog closes.
Monday, December 29, 2014 1:23 PM
What you do is the default behaviour when you show your message using a form with showdialog
If you have a timer in that it does exactly what you ask
Bellow a code sample for the messageform including the removing of the controlbox with the minimize and the close.
Public Class Form2
Private WithEvents tim As New Timer With {.Interval = 3000, .Enabled = True}
Private Sub tim_Tick(sender As Object, e As EventArgs) Handles tim.Tick
Close()
End Sub
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.ControlBox = False
End Sub
End Class
Success
Cor
Monday, December 29, 2014 6:58 PM
Hi, could someone direct me to a good reference for suspending a program temporarily for a few seconds while a message is displayed, say in a Text Box? The purpose is to display a “Program Complete” message for example for a short period within a module, then return to a main program that called the module. Thanks.
Michael Downing
Why should a program have to be suspended for any length of time just because some module completes its code?
Just display that the modules code completed.
Would there be some issue with not suspending a program just because some display says a modules code was completed?
La vida loca
Tuesday, December 30, 2014 8:15 PM
Thanks all for the great suggestions; they led me to another solution which is most suitable for my application:
Threading.Thread.Sleep(10000)
This single line suspends the program for 10 seconds while I display any message desired in a form, then continue with normal program execution.
This concludes the thread.
Michael Downing
Michael,
Assuming you're using that in the form's code, I don't think that's a great solution at all.
You might try this: When the program gets to the point that the threading timer is running, minimize then restore the form.
Do you see a problem there?
Still lost in code, just at a little higher level.
:-)
Wednesday, December 31, 2014 2:06 AM
Frank, you might be right in that this may not be the optimal solution, but it solved my need and it is just cosmetics anyway – I am an accountant and write programs to manipulate large amounts of financial data. But sometimes it is fun to experiment with a little non-essential coding for asthetic reasons. Thanks.
Michael Downing
Wednesday, December 31, 2014 2:08 AM
Sorry, "aesthetic". Have a great New Year's all.
Michael Downing
Wednesday, December 31, 2014 3:47 AM
Thanks all for the great suggestions; they led me to another solution which is most suitable for my application:
Threading.Thread.Sleep(10000)
This single line suspends the program for 10 seconds while I display any message desired in a form, then continue with normal program execution.
This concludes the thread.
Michael Downing
Why not display a simulated or real toast notification for 10 seconds and let the program continue to run?
La vida loca