473,320 Members | 2,164 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

checking TimeofDay against app setting value

maylortaylor
72 64KB
I'm writing a VB console program that will run a function at a certain time of day. This is what i have so far.
Expand|Select|Wrap|Line Numbers
  1. Sub Main()
  2.  
  3.     Dim backupTime As String
  4.  
  5.     backupTime = My.Settings.backupTime
  6.  
  7.  
  8.     Do Until TimeOfDay = backupTime
  9.         Threading.Thread.Sleep(2000)
  10.     Loop
  11.  
  12.     backup()
  13. End Sub
The "backupTime" that is being referred to is stored in the App.Config file

Expand|Select|Wrap|Line Numbers
  1. <userSettings>
  2.     <ZipAJob_Timed.My.MySettings>
  3.         <setting name="backupTime" serializeAs="String">
  4.             <value>#01:59:00 PM#</value>
  5.         </setting>
  6.     </ZipAJob_Timed.My.MySettings>
  7. </userSettings>
The problem is that the "Do While" loop checks every 2 seconds for the "TimeofDay" to match "backupTime". But that can lead to the program not running because it missed the match by 2 seconds. So either i need to have it disregard the seconds or to have the TimeofDay.minutes/hours and backupTime.minutes/hours match only.

I've looked into Parsing..but not exactly sure where i should start.
Feb 22 '13 #1
3 1359
Mikkeee
94 64KB
You should be comparing dates rather than string values. You could bump your time up to every minute and check that.

Expand|Select|Wrap|Line Numbers
  1.    Dim backupTime as DateTime = Date.Parse(My.Settings.backupTime)
  2.    Do
  3.        If DateDiff(DateInterval.Minute, backupTime, Now) = 0 Then
  4.            ' This will trigger when a match is made by the minute
  5.        Else
  6.            ' Sleep for 60 seconds
  7.            Threading.Thread.Sleep(60000)
  8.        End If
  9.    Loop
  10.  
You could also throw a timer on your form and set the interval. This way your app isn't constantly sleeping.
Feb 23 '13 #2
zmbd
5,501 Expert Mod 4TB
agreed on the string vs. date

AND

... instead of looking for just "=" you should be looking the current date/time ">=" to your desired backup time. This way even if the comparison fails, the next step is executed even if the current time is past what you expected.

It depends on your application requirements; however, every 2 seconds seems excessive... imho... even every minute seems too much. Personally, I've never set a backup check for under 5 minutes or on exit of the program. The more frequent the check, the more likely you are to interfere with an end-user.
Feb 23 '13 #3
maylortaylor
72 64KB
I figured out how to solve the problem this way
Expand|Select|Wrap|Line Numbers
  1. Do
  2.  
  3.             If ((Now.Minute() = backupTime.Minute) And (Now.Hour() = backupTime.Hour)) Then
  4.                 backup()
  5.             Else
  6.                 Threading.Thread.Sleep(15000)
  7.             End If
  8.         Loop
Feb 25 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Douha | last post by:
Hi all, I have an XML file where all to elements for the data are contained in CDATA sections. I have a schema created that is working right now although it is pretty dumbed down. I have a need...
0
by: Jason Priebe | last post by:
I posted earlier with a very complex example. This simple one gets to the point much faster. timeofday() seems to behave inconsistently when the timezone is set with "GMT+X" notation. foo=>...
4
by: John Vottero | last post by:
When a class contains a TimeSpan property, XmlSerializer doesn't work. A TimeSpan property is serialized like: <MySpan /> I've read a number of posts that talk about why this happens and how...
5
by: Mark | last post by:
Assume that "some_app_setting" does not exist in my web.config file. Then, the first line of code below assigns the value null to strApplication. Why doesn't my IF statement return true, and...
1
by: excelleinc.com | last post by:
Hi, I'm trying to check if field contains NULL value in MSSQl 2000 database but keep receiving error. asp.net code: If Trim(HLSQLDSet.Tables("mfglinks").Rows(15).Item(0)) Is Null Then...
11
by: Patrick.O.Ige | last post by:
When i try and use this (Where Unit is a column in my Table):- If Unit Is DBNull.Value Then Return "1" Else Return "2" End If I always have 2 returned! Even when Unit is NULL! I want a...
5
by: VB Programmer | last post by:
I have a javascript calculator. How do I pass the value of the calculator result to another ASPX page so that I can right some VB.NET against the value? Thanks!
6
by: Rich | last post by:
Hello, I have a label in my app where I display time from a Timer contol like this: Private Sub Timer1_Tick(...) Handles Timer1.Tick lbl_Time.Text = TimeOfDay.ToString End Sub The display...
19
by: Mike | last post by:
I have a list of numbers, e.g., (1,3,4,5,8,16,20), and am trying to create a simple IF statement to see if the value is in that list. Is there an easier or more efficient way, than the sample code...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.