automatic closing application

.net Bahrain
  • 14 years ago

    i have an application written in vb .net , i want this application to be close for all user at a certain time

    for example close for all user at 12:00 PM, i dont want it to read date and time from windows and check it with 12:00PM because users can esaily change it , i want it to read my sql server time and close at 12:00PM

    any idea how can i implement this ????!!!!!

    please reply as soon as you can any help will be appriciated

     

    Thanks,

    coder

  • 14 years ago

    Read the time from SQL Server.  Calculate the number of milliseconds between that time and the time you want to close the app.  Set that value as the Interval for a Timer and enable it.  In the Tick/Elapsed event of the Timer you close the app.

    Note that if you want it to close the app right on that time whether the user is doing something or not then you will have to ensure that your Timer raises its events in a background thread.  That means that you cannot use a Windows.Forms.Timer.  You would have to use a Timers.Timer and do not set its SynchronizingObject property to a UI element, otherwise it too will raise its events in the thread that owns that object, i.e. the UI thread.



  • 14 years ago

    Thank you jmcilhinney but can you explain more about the timers.timer and if you have any links and any similar coding will be appreciated

     

    Coder

  • 14 years ago

    If you're using VS.NET 2003 then it's available from the Components section in the Toolbox.  If you're using 2005 (Express at least, not sure about Pro) then it's not in the Toolbox by default.  You can add one in code or you can add it to your Toolbox and then add one in the designer.  Below is a link to an article that compares the different types of Timers in the .NET Framework.  If you want to know more about Timer class, or any class for that matter, then you don't need links from me.  Just go to MSDN and search for "timer class" (without quotes).

    Comparing Timers







  • 14 years ago

    hi jmcilhinney thanks alot for your help ,

    this is my code :

    Private WithEvents tmr As System.Timers.Timer

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

    tmr =

    New System.Timers.Timer

    tmr.Interval = 2000

    tmr.Start()

    End Sub

    Private Sub tmr_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tmr.Elapsed

    MsgBox("hello")

    tmr.Stop()

    Me.Close()

    End Sub

Post a reply

Enter your message below

Sign in or Join us (it's free).

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone” - Bjarne Stroustrup