473,387 Members | 1,516 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,387 software developers and data experts.

Timer in Console application

Hi all,

I have developed a vb.net console application which will run some code
every [x] seconds. To get this working I used a timer "System.Timers".
When I start my console application it exits within a second. So I
added the line: "Console.Read()". Everything seemes to run fine but
after a few days the application stopped. Without an error.
I think it has something to do with the lifetime of the
"Console.Read()". Is this right?

Is there another trick to solve this timer problem?

Thanks,

Aart

Dec 29 '05 #1
6 19730
I forgot to add the code.
<cut>
Dim TimerInterval As Integer = m_Settings.GetValue("TimerInterval",
GetType(String))
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent
aTimer.Interval = TimerInterval
aTimer.Enabled = True
aTimer.AutoReset = True
Console.WriteLine("Wacht op aflopen timer [" &
m_Settings.GetValue("TimerInterval", GetType(Integer)) / 1000 & "
sec.]")
Console.Read()
</cut>

Dec 29 '05 #2
why not just replace with an infinite loop with a sleep in?
"Aart Nicolai" <aa*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,

I have developed a vb.net console application which will run some code
every [x] seconds. To get this working I used a timer "System.Timers".
When I start my console application it exits within a second. So I
added the line: "Console.Read()". Everything seemes to run fine but
after a few days the application stopped. Without an error.
I think it has something to do with the lifetime of the
"Console.Read()". Is this right?

Is there another trick to solve this timer problem?

Thanks,

Aart

Dec 29 '05 #3
or better still, using the threading class'es timer within your loop

ie
do
threading.threading.sleep(5000) ' sleep for 5 seconds

' Do your stuff here

loop until false ' I think you can use this for an infinite loop
"Simon Verona" <no****@nomail.zzz> wrote in message
news:u2**************@TK2MSFTNGP15.phx.gbl...
why not just replace with an infinite loop with a sleep in?
"Aart Nicolai" <aa*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,

I have developed a vb.net console application which will run some code
every [x] seconds. To get this working I used a timer "System.Timers".
When I start my console application it exits within a second. So I
added the line: "Console.Read()". Everything seemes to run fine but
after a few days the application stopped. Without an error.
I think it has something to do with the lifetime of the
"Console.Read()". Is this right?

Is there another trick to solve this timer problem?

Thanks,

Aart


Dec 29 '05 #4
On Thu, 29 Dec 2005 15:17:20 -0000, "Simon Verona" <no****@nomail.zzz>
wrote:

or even better, the multimedia timer tha runs in its own thread that
you configure as a callback function
or better still, using the threading class'es timer within your loop
ie
do
threading.threading.sleep(5000) ' sleep for 5 seconds
' Do your stuff here

loop until false ' I think you can use this for an infinite loop
"Simon Verona" <no****@nomail.zzz> wrote in message
news:u2**************@TK2MSFTNGP15.phx.gbl...
why not just replace with an infinite loop with a sleep in?
"Aart Nicolai" <aa*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi all,

I have developed a vb.net console application which will run some code
every [x] seconds. To get this working I used a timer "System.Timers".
When I start my console application it exits within a second. So I
added the line: "Console.Read()". Everything seemes to run fine but
after a few days the application stopped. Without an error.
I think it has something to do with the lifetime of the
"Console.Read()". Is this right?

Is there another trick to solve this timer problem?

Thanks,

Aart




Dec 30 '05 #5
Aart,
Rather then use a Console application, have you considered a Windows Service
application?

As a Windows Service are designed to run "forever", plus they can be started
when the machine starts, rather then require someone to log in.

If your app "needs" to be a Console application, as the others suggests, you
need to prevent your Main from exiting. I would probably use a Mutex,
AutoResetEvent, or ManualResetEvent (favoring the reset events over the
mutex) to keep it from exiting. This way the timer thread can have the main
thread exit if the timer thread decides its "done". By timer thread I mean
the thread where the System.Timers.Timer Elapsed event is raised...

Post if you want help with the reset events or the windows service.
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Aart Nicolai" <aa*********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
| Hi all,
|
| I have developed a vb.net console application which will run some code
| every [x] seconds. To get this working I used a timer "System.Timers".
| When I start my console application it exits within a second. So I
| added the line: "Console.Read()". Everything seemes to run fine but
| after a few days the application stopped. Without an error.
| I think it has something to do with the lifetime of the
| "Console.Read()". Is this right?
|
| Is there another trick to solve this timer problem?
|
| Thanks,
|
| Aart
|
Jan 3 '06 #6
Thanks, I think I will transform it into a windows service..

Jan 4 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

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...
11
by: avivgur | last post by:
Hello, I have devised a console application that uses a System.Timers.Timer and its Elapsed event. The problem is that I want the program to continue to run so that each time the event is raised,...
3
by: jam | last post by:
Dear all, I am wrtiing a console application and doing some test on timer, the below is my sample code I got from some site, but I cannot make it work... Error is 'System.Timers.Timer' does not...
4
by: VB Programmer | last post by:
I'm creating a console application. Can I use a timer control to do something every 5 seconds?
4
by: archana | last post by:
Hi all I am having application which is using server based timer that is timer from namespace system.timer. I am having windows service which i want to run after every 1 hour and after...
4
by: Lauren Quantrell | last post by:
I have just put together a vb.net app and now need to provide it to users. This application needs to run the code in a sub every 60 seconds from a Windows Service application. I have the...
10
by: Joris De Groote | last post by:
Hi, I have wrote a program that checks for files and moves these files to the correct folders when they come in. Everything works fine. However I always have to start that program manually. I...
11
by: Hotrod2000 | last post by:
I'm quite new to programming but I'm having problems getting a timer to work in visual studio.net I've created a timer on a form, enabled it and then typed the following code (from the mdsn...
16
by: Peter Oliphant | last post by:
Note that although this involves SAPI, it is more a question about Timers and event handlers. I wrote a Speech Recognize handler (SAPI), and put some code in it to enable a Timer. It would not...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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
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,...
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...

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.