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

Timer for program (non graphic)

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 have been trying to make the program
(wich has no UI) to keep running and let it execute everything once every
few minutes (depending on how the timer is set).

Can anyone tell me how I can get a timer in the program so the program keeps
running? I can add a timer, but the program just quits when everything has
run. I don't want it to close.

Thanks
Joris
Jun 2 '07 #1
10 1814

"Joris De Groote" <jo************@skynet.bewrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
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 have been trying to make the
program (wich has no UI) to keep running and let it execute everything
once every few minutes (depending on how the timer is set).
Are you using a Console Application?
>
Can anyone tell me how I can get a timer in the program so the program
keeps running? I can add a timer, but the program just quits when
everything has run. I don't want it to close.
You are using the System.Timer namespace?

This example came from VS Help for VB.

Imports System
Imports System.Timers

Public Class Timer1

Public Shared Sub Main()
' Normally, the timer is declared at the class level, so
' that it doesn't go out of scope when the method ends.
' In this example, the timer is needed only while Main
' is executing. However, KeepAlive must be used at the
' end of Main, to prevent the JIT compiler from allowing
' aggressive garbage collection to occur before Main
' ends.
Dim aTimer As New System.Timers.Timer()

' Hook up the Elapsed event for the timer.
AddHandler aTimer.Elapsed, AddressOf OnTimedEvent

' Set the Interval to 2 seconds (2000 milliseconds).
aTimer.Interval = 2000
aTimer.Enabled = True

Console.WriteLine("Press the Enter key to exit the program.")
Console.ReadLine()

' Keep the timer alive until the end of Main.
GC.KeepAlive(aTimer)
End Sub

' Specify what you want to happen when the Elapsed event is
' raised.
Private Shared Sub OnTimedEvent(source As Object, e As ElapsedEventArgs)
Console.WriteLine("Hello World!")
End Sub
End Class

You do know about the FileSystemWatcher where it will check for a file
coming in to a folder and fire an event.

http://www.google.com/search?hl=en&q...=Google+Search

Jun 2 '07 #2
Joris,

This needs to be a "Service" instead of a console application.

Cor

"Joris De Groote" <jo************@skynet.beschreef in bericht
news:%2****************@TK2MSFTNGP05.phx.gbl...
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 have been trying to make the
program (wich has no UI) to keep running and let it execute everything
once every few minutes (depending on how the timer is set).

Can anyone tell me how I can get a timer in the program so the program
keeps running? I can add a timer, but the program just quits when
everything has run. I don't want it to close.

Thanks
Joris

Jun 3 '07 #3

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...
Joris,

This needs to be a "Service" instead of a console application.
Why? One can certainly build a console application that will stay up and
running 24/7*365, until one tells it to shutdown, and it do everything that
a Service application can do in regards to the OP's solution.

Jun 3 '07 #4

Then when would you use a Service for me is this a typical way were a
service fits the best.
You can use a windows application as well for this, but for me it is as
using a bicycle to transport a piano.
It can be done.

Cor

"Mr. Arnold" <MR. Ar****@Arnold.comschreef in bericht
news:ON**************@TK2MSFTNGP02.phx.gbl...
>
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:Om**************@TK2MSFTNGP02.phx.gbl...
>Joris,

This needs to be a "Service" instead of a console application.

Why? One can certainly build a console application that will stay up and
running 24/7*365, until one tells it to shutdown, and it do everything
that a Service application can do in regards to the OP's solution.

Jun 3 '07 #5

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>
Then when would you use a Service for me is this a typical way were a
service fits the best.
In this simple solution of an application using a timer and polling for
files in a directory, then why would the OP need a service to do it? I don't
see the reasoning

When I need an application to be monitored by a Human Being showing status,
progress, mission critical situations, etc, etc, then I'll use a Console
Application for that purpose.

If I need an application that can run unattended and be assured that the
application will be started again by itself if the machine is rebooted, then
I'll use a Service.

But you can do the same with an Console Appliaction as far as a machine
restart, with O/S or 3rd party solutions utilities.

You can use a windows application as well for this, but for me it is as
using a bicycle to transport a piano.
A Windows application and a Console Application are two different things.

I have used Service and Console applications to do many things. And to be
honest, there is nothing I couldn't have done with a Service application
that I couldn't have done with a Console application that I have seen to
this point.

It all depends upon what the customer wants. If they wanted it to be a NT
Service application, then that's what they got. If they wanted to be a
Console application, then that's what they got.

Both of the solutions have the power to produce powerful .NET applications,
no doubt about it from my view point, with both being trucks to transport
that paino.

Jun 3 '07 #6
Feel free, feel free, I only told the OP that in my opinion a Service was
more dedicated to his problem. I know that it can be done with every
application. Even without it by puting it in the scheduler.

Cor

"Mr. Arnold" <MR. Ar****@Arnold.comschreef in bericht
news:Or**************@TK2MSFTNGP04.phx.gbl...
>
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>
Then when would you use a Service for me is this a typical way were a
service fits the best.

In this simple solution of an application using a timer and polling for
files in a directory, then why would the OP need a service to do it? I
don't see the reasoning

When I need an application to be monitored by a Human Being showing
status, progress, mission critical situations, etc, etc, then I'll use a
Console Application for that purpose.

If I need an application that can run unattended and be assured that the
application will be started again by itself if the machine is rebooted,
then I'll use a Service.

But you can do the same with an Console Appliaction as far as a machine
restart, with O/S or 3rd party solutions utilities.

>You can use a windows application as well for this, but for me it is as
using a bicycle to transport a piano.

A Windows application and a Console Application are two different things.

I have used Service and Console applications to do many things. And to be
honest, there is nothing I couldn't have done with a Service application
that I couldn't have done with a Console application that I have seen to
this point.

It all depends upon what the customer wants. If they wanted it to be a NT
Service application, then that's what they got. If they wanted to be a
Console application, then that's what they got.

Both of the solutions have the power to produce powerful .NET
applications, no doubt about it from my view point, with both being trucks
to transport that paino.

Jun 3 '07 #7

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:O$****************@TK2MSFTNGP04.phx.gbl...
Feel free, feel free, I only told the OP that in my opinion a Service was
more dedicated to his problem. I know that it can be done with every
application. Even without it by puting it in the scheduler.

Cor

"Mr. Arnold" <MR. Ar****@Arnold.comschreef in bericht
news:Or**************@TK2MSFTNGP04.phx.gbl...
>>
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>>>
Then when would you use a Service for me is this a typical way were a
service fits the best.

In this simple solution of an application using a timer and polling for
files in a directory, then why would the OP need a service to do it? I
don't see the reasoning

When I need an application to be monitored by a Human Being showing
status, progress, mission critical situations, etc, etc, then I'll use a
Console Application for that purpose.

If I need an application that can run unattended and be assured that the
application will be started again by itself if the machine is rebooted,
then I'll use a Service.

But you can do the same with an Console Appliaction as far as a machine
restart, with O/S or 3rd party solutions utilities.

>>You can use a windows application as well for this, but for me it is as
using a bicycle to transport a piano.

A Windows application and a Console Application are two different things.

I have used Service and Console applications to do many things. And to be
honest, there is nothing I couldn't have done with a Service application
that I couldn't have done with a Console application that I have seen to
this point.

It all depends upon what the customer wants. If they wanted it to be a NT
Service application, then that's what they got. If they wanted to be a
Console application, then that's what they got.

Both of the solutions have the power to produce powerful .NET
applications, no doubt about it from my view point, with both being
trucks to transport that paino.

Jun 3 '07 #8

Even without it by puting it in the scheduler.
I don't know what you are referring to here on this one, as you can
instantiate a timer off of the System.Timers.Timer in a Console as well as a
Service application to control time intervals, as well as Threads using
intervals.

Like I said, you can keep a Console application up and running 24/7*365, you
can have a Console restarted on a reboot, using the O/S Batch file system,
other O/S tools or other 3rd party tools and it can do just about anything a
Service can do in regards to creating or running a powerful .Net solution,
with few exceptions or limitations.

A Console application is on par with a Service application, if one knows how
to design and implement an application using the solution. It's more than a
bicycle, MVP.
Jun 3 '07 #9
For what is the is the program from Joris build for.

To communicate with clients over a console (Typical console operation)

To move files to other places smoothly done as there is time for that.
(Typical service operation)

That a lot of people use a Console operation because it act as a former Dos
operation (including Microsoft often does using old NT scripts), does not
mean that it is build for that.

Cor
"Mr. Arnold" <MR. Ar****@Arnold.comschreef in bericht
news:%2****************@TK2MSFTNGP02.phx.gbl...
>
>Even without it by puting it in the scheduler.

I don't know what you are referring to here on this one, as you can
instantiate a timer off of the System.Timers.Timer in a Console as well as
a Service application to control time intervals, as well as Threads using
intervals.

Like I said, you can keep a Console application up and running 24/7*365,
you can have a Console restarted on a reboot, using the O/S Batch file
system, other O/S tools or other 3rd party tools and it can do just about
anything a Service can do in regards to creating or running a powerful
.Net solution, with few exceptions or limitations.

A Console application is on par with a Service application, if one knows
how to design and implement an application using the solution. It's more
than a bicycle, MVP.


Jun 4 '07 #10

"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:ev**************@TK2MSFTNGP06.phx.gbl...
For what is the is the program from Joris build for.

To communicate with clients over a console (Typical console operation)
That would be when necessary. You can communicate to an Event log as well
just like you can with NT service application. As a matter of fact, you can
have a screen sitting there that a NT Service application can communicate
to as well and you can call that a console if you like.
>
To move files to other places smoothly done as there is time for that.
(Typical service operation)
I disagree as I have done it with both solutions. I have also gone out over
HTTP to connect to a Web service pulling XML data from the site, writing
files down to a file directory queue, processing those files (1, 000's of
them at a time) or processing was done on the fly in memory, extracted the
data from XML files or from memory to SQL Server or Oracle databases with
adds, updates and deletes in a ADO.NET transactional mode, using Oops
programming techniques in both solutions.

I did it first with .NET NT Service applications in C# and VB .NET. Then
when called to do the same thing with a .NET Console application, because
that's what the client wanted, I was able to do the same thing with .NET
Console solutions.

Both solutions being used had the ability to create XML serialized object
files down to a directory with sending the files off to other directories
local or over the LAN to be processed to Shares. Both .NET Console and NT
Service applications ran 24/7*365, which one being just a powerful as the
other.

BTW, these were multi threaded solutions.
>
That a lot of people use a Console operation because it act as a former
Dos operation (including Microsoft often does using old NT scripts), does
not mean that it is build for that.
I guess .NET allows one to surpass the limitations you see with a Console
application , because I have done some serious things with both solutions,
that ran as smooth as a baby's bottom.

Maybe, I am too naive to know that I am not suppose to be doing this with a
Console application. <g>
Jun 4 '07 #11

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

Similar topics

4
by: Ryan Gregg | last post by:
I've got a background service running that needs to check a database periodically and print reports whenever it finds that the data has changed. I've built a class library that scans the database...
14
by: Mathieu | last post by:
Hi all, I just want to know how to use a System.Windows.Forms.Timer in class. I know how to use it on a form, but I don't know how to "put" a timer in a class (DLL) Thx !!!
10
by: WhiteSocksGuy | last post by:
Help! I am new to Visual Basic .Net (version 2002) and I am trying to get a System.Timers.Timer to work for me to display a splash screen for about two seconds and then load the main form. I have...
10
by: moti | last post by:
I need to check for the existence of a file (the filename and folder are known). The file may be created at any time, before or after the start of the file check. As I do not want to burden the...
5
by: Michael C# | last post by:
Hi all, I set up a System.Timers.Time in my app. The code basically just updates the screen, but since the processing performed is so CPU-intensive, I wanted to make sure it gets updated...
27
by: jeniffer | last post by:
I need to create an excel file through a C program and then to populate it.How can it be done?
0
by: Jvzj017 | last post by:
For this assignment you will write a function which takes as parameters the upper left corner of a button and a string representing the "label" of the button. The function will write the label to the...
6
by: André | last post by:
Hi, I made a webform for a survey, with multiple-choice questions. The results of each question is put into a table e.g.: values frequency 1 6 2 3 3 32 4 ...
8
by: Rainer Queck | last post by:
Hello NG, in my application I have a Panel, docked right to my Form. On this panel I draw - cyclic triggered by a System.Winforms.Timer - a bitmap using the Graphics class. using (Graphics g =...
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
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
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
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...
0
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...
0
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,...

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.