Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 303
  • Last Modified:

Close Messagebox

In Windows applications, is there a way to close a messagebox within certain amount of time?

Try
      'my code

catch

      messagebox.show("Error")  << I want this messagebox to be closed after an hour

end
0
VBdotnet2005
Asked:
VBdotnet2005
2 Solutions
 
quizwedgeCommented:
You'll need to use threading and a timer. There are a few examples at  http://www.vbforums.com/showthread.php?605979-self-closing-message-box&s=d05590a61b90627b83e96207c9cf069e&p=3745046#post3745046

The idea is that call New Threading.Thread(AddressOf closeMsgBox) where closeMsgBox is a function that sends keyboard events to close the MsgBox.

The closeMsgBox code from the site above is

Private Sub closeMsgbox(ByVal delay As Object)
        Threading.Thread.Sleep(CInt(delay) * 1000)
        AppActivate(Me.Text)
        keybd_event(VK_RETURN, 0, KEYEVENTF_KEYDOWN, 0)
        keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0)
    End Sub

Open in new window

0
 
Jacques Bourgeois (James Burger)Commented:
MessageBox is a modal or dialog window and requires user intervention.

Not a good one. You could use a SendKeys command to send keys to the keyboard processor, and thus simulate user interaction, but it is always dangerous to do because you cannot control which application will receive the keys. After an hour, you can almost be sure that another application will have the focus and will get the keys, which might cause problems in that application.

The only good way to do it is to display a form that you created and set a timer to close it.
0
 
quizwedgeCommented:
I missed that you wanted it to close after an hour. Custom form is the best way to go. Another option would be to have the timer give your app focus, but you still risk annoying the user because they're in the middle of typing something.
0
 
Éric MoreauSenior .Net ConsultantCommented:
0
 
James AtkinSenior Principle Software EngineerCommented:
Hi,

I have used this in the past - seemed to work well:

http://www.codeproject.com/Articles/7968/MessageBox-with-a-timeout-for-NET

Hope this helps,

James
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now