Need to edge out the competition for your dream job? Train for certifications today.
Public Class Form1
Private TargetDateTime As DateTime
Private ShutDownDateTime As DateTime
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
' Start with today's date:
Dim TargetDateTime As DateTime = DateTime.Today
' Get the next Saturday:
While TargetDateTime.DayOfWeek <> DayOfWeek.Saturday
TargetDateTime = TargetDateTime.AddDays(1)
' Pick a specific Time on that Saturday:
' Example --> 3:30 P.M.
TargetDateTime = TargetDateTime.Add(New TimeSpan(15, 30, 0)) ' <-- hours are in 24 hour format!
' If the current time is already past the target time for that Saturday, set it up for next week's Satuday Date/Time:
If DateTime.Now.Subtract(TargetDateTime).TotalMilliseconds > 0 Then
TargetDateTime = TargetDateTime.AddDays(7)
' Setup the Timer() Interval so it fires at the target DateTime:
Timer1.Interval = TargetDateTime.Subtract(DateTime.Now).TotalMilliseconds
' Setup the ShutDown DateTime for 30 minutes after the Target DateTime:
ShutDownDateTime = TargetDateTime.AddMinutes(30)
Private Sub Timer1_Tick(sender As Object, e As System.EventArgs) Handles Timer1.Tick
' Are we past the shut down time?
If DateTime.Now.Subtract(ShutDownDateTime).TotalMilliseconds > 0 Then
Me.Close() ' shut down the application
' ... not past the shut down time so it must be time to do some work ...
' Change the Interval for the ShutDown DateTime:
Timer1.Interval = ShutDownDateTime.Subtract(DateTime.Now).TotalMilliseconds
' ... start your work in here ...
' Use the BackgroundWorker() control to fire the work off in a background thread
Open in new window
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.