Question backup on time selection

bionide

New member
Joined
Apr 10, 2009
Messages
2
Programming Experience
Beginner
Hey guys, im kind of new to VB and im making a program for my dad to backup his hard drives nightly.

So heres my code im having trouble with.

VB.NET:
        If Time.Text = "Instant" Then
            ' If mirrorcopy then warn the user.

            ' Reset variables
            _stopped = False

            ' Create the FileCopy class which will initiate the threads
            CopyFiles = New FileCopy


            CopyFiles.FromPath = FromPathTextbox.Text
            CopyFiles.ToPath = ToPathTextbox.Text
            CopyFiles.InitialMessage = "*** MODE IS WINFORMS ***"
            If CopyFiles.MirrorCopy Then
                CopyFiles.InitialMessage = "*** MODE IS WINFORMS - MIRROR COPY IS SET ***"
            End If
            If CopyFiles.QuietLog Then
                CopyFiles.InitialMessage += vbCrLf & "Logging is quiet - not verbose."
            Else
                CopyFiles.InitialMessage += vbCrLf & "Logging is not quiet - its verbose."
            End If

            ' Initiate the copy, count and mirror threads from the FileCopy class
            CopyFiles.StartCopy()

            WorkingBar.Minimum = 0
            WorkingBar.Maximum = 100
            WorkingLabel.Visible = True
            WorkingBar.Visible = True

            ' Reset form controls
            StartCopy.Enabled = False
            StopCopy.Enabled = True
            ViewLog.Enabled = True
        End If
        If Time.Text = "12:00 PM" Then

        End If

Basically, im wondering how i can make it so when people select 12:00 PM, my program will grab the user's time and sleep until it get to the selected time.

Thanks :p
 
Create a timer, that ticks once an hour. In the timer tick event handler:

VB.NET:
If Time.Text = "Instant" OrElse DateTime.Now.Hour = Int32.Parse(Time.Text)Then
  'Backup Code Goes here
End If

Though you probably don't want just a text box for the time. Probably a combo box or something similar. The above code won't work exactly as is because Time.Text isn't an integer in the way you have it.

Also, it may be better as a windows service, where you set the time to backup in a config file. Then instead of a timer:

VB.NET:
'get time from config file, store in intHour
While True
  If DateTime.Now.Hour = intHour
    'Backup Code Here
  Else
   System.Threading.CurrentThread.Sleep(3600000) 'sleep for one hour
  End If
Loop
 
Back
Top