473,520 Members | 2,710 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

If time equals to...

maylortaylor
72 New Member
I'm trying to have my console app program zip files from an XML file. That part is done; but now, to add more of a headache, i want this action to happen only at certain times.

So, what i'm think is something similar to this

Expand|Select|Wrap|Line Numbers
  1. Dim clocktime = Format(TimeOfDay, "Long Time")
  2.         If clocktime = #1:26:00 PM# Then
and then add all of my code that normally would run. The problem with this method is that when i run the program, it immediately closes b/c it isn't that time. So, my question is...how do i have the program continously check for the time and only run the "if statement" at a certain time.
Dec 6 '12 #1
4 3377
zmbd
5,501 Recognized Expert Moderator Expert
You have not posted enough of your code for anyone to help...
Dec 6 '12 #2
Rabbit
12,516 Recognized Expert Moderator MVP
Use an infinite loop to continuously run the code.

Also, put in a pause so that it's only checking every minute or so. You don't want it to actually check constantly.

And your run condition really shouldn't be an exact time. Rather, it should run if it's past a certain time in case the process gets to the check one second after the run time. But of course that brings up another problem in that it will run continuously after that time. What you can do is put in a longer wait after it runs, or keep track of the last run date and only run if it hasn't yet for that day.

I'm not sure how the program will react when comparing a string against a date so you may want to play on the safe side and have it return a 24-hour time instead.
Dec 6 '12 #3
maylortaylor
72 New Member
Figured it out thanks to the manager.

Expand|Select|Wrap|Line Numbers
  1. Sub Main()
  2.  
  3.         If Now.Hour = 16 And Now.Minute = 57 Then
  4.             runBackup()
  5.  
  6.         End If
  7.  
  8.         Threading.Thread.Sleep(2000)
  9.         Main()
  10.     End Sub
The
Expand|Select|Wrap|Line Numbers
  1. runBackup()
code is where i have the actions to be done at the particular time.
Dec 6 '12 #4
Rabbit
12,516 Recognized Expert Moderator MVP
You don't want to do it that way. At some point you're going to overflow. Use an infinite loop instead. Calling a function infinitely is dangerous.

And you really should run the time check in the way I suggested in post #3. If for some reason the thread gets pushed down in the priority far enough or if the CPU gets hung up for even a minute, the update may end up not running.
Dec 6 '12 #5

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

Similar topics

17
7431
by: Zeng | last post by:
I'm trying to comparing 2 objects (pointer to object) to see if they are the "same" as each other. Here is what the definition of being the "same" object type for both objects, object 1, object 2, same? ----------------------------------------------------------- Decimal 199677 199677 yes String ...
4
3196
by: Chris | last post by:
This is something that has been bugging me for some time. When exactly should I be using == instead of .Equals() ? I see a lot of code that performs object evaluation e.g. Is Object1 the same as Object2 by using == which works but shouldn't it be using .Equals()? e.g. Object1.Equals(Object2) I believe == should be using for simple type...
18
4705
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the class where only the "searched" property has a value. I expected to get the index into the arraylist where I could then get the entire class...
3
2014
by: cj | last post by:
If I want to check to see if it's after "11:36 pm" what would I write? I'm sure it's easy but I'm getting tired of having to work with dates and times. Sometimes I just want time or date. And to be able to do comparisons on them.
12
2190
by: cody | last post by:
Why can I overload operator== and operator!= separately having different implementations and additionally I can override equals() also having a different implementation. Why not forbid overloading of == and != but instead translate each call of objA==objB automatically in System.Object.Equals(objA, objB). This would remove inconsistencies...
3
2699
by: Fir5tSight | last post by:
Hi All, I have two identical PDF files, say file1 and file2. I used an API package to extract the bitmap in each PDF file, say bitmap1 (in file1) and bitmap2 (in file2). Since the bitmaps are same in both files, I expect bitmap1.Equals (bitmap2) to return true. However, it's false. FYI: 1) I've copied file1 to file2, therefore, the...
5
2376
by: taumuon | last post by:
I've got an object, Person, that supports IEquatable<Person>. It implements bool Equals(Person obj) as well as overriding bool Equals(object obj) I've got a container type that holds a member object of generic type T, that supports IEquatable<T>, and a method, DoComparisons(T obj) to compare the member object to the object passed in.
10
105004
by: r035198x | last post by:
The Object class has five non final methods namely equals, hashCode, toString, clone, and finalize. These were designed to be overridden according to specific general contracts. Other classes that make use of these methods assume that the methods obey these contracts so it is necessary to ensure that if your classes override these methods, they...
7
2658
by: =?Utf-8?B?QWxleCBDb2hu?= | last post by:
In C++, there is an easy technique to provide an overloaded Equals() method. A straightforward translation to C# causes a stack overflow. Why does b.Equals(ba) in the snippet below not understand that it should call (ba as B).Equals(b) inside? Thanks in advance, Alex code sample follows:
1
1155
by: cronusf | last post by:
In my book they give a sample Complex class implementation and it implements: override bool Equals(object rhs) {...} public book Equals(Complex rhs) // IEquatable<Complex> {...} public static bool operator==(Complex lhs, Complex rhs)
0
7299
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7438
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7559
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5125
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3279
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1646
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
506
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.