Solved

How to shut app down after 30 Min. VB.net 2005

Posted on 2010-11-10
9
600 Views
Last Modified: 2012-05-10
How can I shut down my app 30 min. after it has been started?
0
Comment
Question by:TEStack
9 Comments
 
LVL 1

Accepted Solution

by:
MartinHouse earned 500 total points
ID: 34104336
Hi, you've not given much detail - You're usijng VB.net 2005 so I assume it's a VB.net app you want to close down ?  If that's case then when the app starts record time that you want the app to close:  e.g.

        Dim CloseTime As DateTime

        CloseTime = Now
        CloseTime.AddMinutes(30)

Elsewhere in your app,have a time on a form which fires every ( say 0 minute, and in that timer event, check the time

if CloseTime > now then
0
 
LVL 1

Expert Comment

by:MartinHouse
ID: 34104357
    Application.exit
end if

Obviously, your application termination will need to be tidies to release any resources in use etc.

Hope this helps

Mart
0
 
LVL 17

Expert Comment

by:Zhaolai
ID: 34105056
Add a Timer to your main form. In the Form_Load event, set the timer's interval to 30*60*1000 (30 minutes), like this: Timer1.Interval = 30*60*1000.
Then add the following code:

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Application.Exit()
    End Sub
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 34105812
You can also use a background thread and just put it to sleep:
Public Class Form1



    Private AutoCloseThread As System.Threading.Thread



    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        AutoCloseThread = New System.Threading.Thread(AddressOf Sleeper)

        AutoCloseThread.IsBackground = True

        AutoCloseThread.Start()

    End Sub



    Private Sub Sleeper()

        Dim ts As TimeSpan = TimeSpan.FromMinutes(30)

        System.Threading.Thread.Sleep(ts.TotalMilliseconds)

        Application.Exit()

    End Sub



End Class

Open in new window

0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 5

Expert Comment

by:andr_gin
ID: 34111131
You have several ways of exiting your application:

1.) If you have only 1 working thread without long blocking calls you can simply check, if DateTime.Now.Ticks < StartTime.AddMinutes(30).Ticks. If this is the case release all ressources and end your application. This is the softest way

2.) You can use the Timer and if it is elapsed call YourMainForm.Close. Then you can release all ressources and close, but this does not work, while the main GUI thread is not idle.

3.) You can start a new Thread that calls Thread.Sleep(30*60*1000) and then calls Application.Exit

4.) If you want to do it the hard way you can start your program from another program with Process.Start, then call Thread.Sleep(30*60*1000) afterwards and then uses Process.Kill to end the program. This will nearly always work, but you have no chance to release all ressources.

You can also use a combined solution to end the program the soft way after 30min and if it is not closed after 31min you can call Proces.Kill.

P.S.: I havent tried yet, but I think it is not possible to kill your own process.
Application.Exit() is a soft way of exiting your application. If you really want to be sure that it closes, you have to start it from another process, call Thread.Sleep(30*60*100) and call Process.Kill afterwards.
0
 

Author Comment

by:TEStack
ID: 34119202
I believe that I did not ask the question properly.  I actually need the VB App to close 30 min after a button is pressed.  I've tried the above code under a button sub, but the timer never appeared to change.
0
 

Author Comment

by:TEStack
ID: 34119550
MartinHouse, I was finally able to make it work.  Thanks for the help!
0
 

Author Closing Comment

by:TEStack
ID: 34119553
I appreciate the help!
0
 
LVL 1

Expert Comment

by:MartinHouse
ID: 34121747
You're welcome.  Pleased to have helped :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now