473,395 Members | 2,467 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,395 software developers and data experts.

Trying to get Threading.Timer to do a function everyday at a specific

Hey,

I've been trying to get this part of my code to work but it hasn't done anything. I'm trying to create a function that sends an email everyday at a specific time. I thought threading.timer would work but i haven't figured it out yet. I don't get errors when its executed but it also does nothing. If someone could tell me whats going on with this piece of code, i would greatly appreciate it. Thanks

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. Shared timer As System.Threading.Timer
  4.  
  5.         Public Sub Main(ByVal args As String())
  6.             'get today's date at 9:00 AM
  7.             Dim nineAM As DateTime = DateTime.Today.AddHours(9)
  8.  
  9.             'if 9:00AM has passed, get tomorrow at 9:00 AM
  10.             If DateTime.Now > nineAM Then
  11.                 nineAM = nineAM.AddDays(1)
  12.             End If
  13.  
  14.             ' calculate milliseconds until the next 9:00AM
  15.             Dim FirstExecution As Integer = CInt(Math.Truncate(nineAM.Subtract(DateTime.Now).TotalMilliseconds))
  16.  
  17.             ' calculate the number of milliseconds in 24 hours
  18.             Dim TimeSpan As Integer = CInt(Math.Truncate(New TimeSpan(24, 0, 0).TotalMilliseconds))
  19.  
  20.             'set the method to execute when the time executes
  21.             Dim ExecuteEmail As TimerCallback = AddressOf Email
  22.  
  23.             'start the timer. The timer will execute "Email" when the number of seconds between now
  24.             'the next 9:00 AM elapse. After that, it will execute every 24 hours
  25.             Dim timer As New System.Threading.Timer(ExecuteEmail, Nothing, FirstExecution, TimeSpan)
  26.  
  27.             'Block the main thread forever. The timer will continue to execute
  28.             Thread.Sleep(Timeout.Infinite)
  29.  
  30.         End Sub 
Jun 9 '10 #1
1 1759
Plater
7,872 Expert 4TB
Ok, hmmm. And you have verified that the numbers are correct, and left the program running the entire time it needs to? (Because shutting it down and starting it up would make it "skip" probably)

How about making the timer execute every 30secs and checking the time inside the timer's function?
Jun 9 '10 #2

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

Similar topics

4
by: Hagay Lupesko | last post by:
Hi, I've encountered a strange phenomena which appears to me as a bug: I have an engine that uses a System.Threading.Timer to invoke a delegate every X minutes. The code looks something...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
1
by: Paul Tomlinson | last post by:
Question about a System.Threading.Timer object and the "state" object you pass to it... Timer stateTimer = new Timer( = new TimerCallback( OnTimer ), o, 1000, 1000); I have an array of timer...
2
by: linesh.gajera | last post by:
Hi Guys, I am creating a Windows service that call a routine at given interval. Once routine is complete, windows service should wait for 5 minutes and then call the routine again. I was using...
2
by: steve | last post by:
Since System.Threading.Timer uses the threadpool to do its stuff what happens when (a) You try to create a timer and the thread pool is *exhausted* (b) The timer is due to fire AND all threads...
6
by: whtinkm | last post by:
Hi, All Recently, my project need some code like following: using System; using System.Threading; namespace MyTimerTest { class Class1 {
3
by: mjheitland | last post by:
Hi, I like to know how many threads are used by a Threading.Timer object. When I create a Threading.Timer object calling a short running method every 5 seconds I expected to have one additional...
3
by: Daniel Maycock via .NET 247 | last post by:
I can't get my threading timer to show a splash screen panel for six seconds, then move onto the next panel. The timer just doesn't tick (this is aparent when I set the time to wait to 100 and it...
8
by: KnighT | last post by:
I have a .net service that runs a System.Threading.Timer. The delegate points to the function that the service should execute when the timer elapses. Problem: The timer is not ticking. I have...
1
by: sarabonn | last post by:
Hallo everyone, I am using vs 2005 with vb.net. I want to run a windows service once a day automatically. I used the threading timer and it runs perfect for the first and does not run...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.