Advertisement

05.15.2008 at 07:36AM PDT, ID: 23405289
[x]
Attachment Details

Run code every minute

Asked by astromex in Microsoft Visual C#.Net, .NET, C# Programming Language

Tags: c#

Hi.
I need an efficient method of running a piece of code every minute.

I am writing a Windows Service, an I need it to perform a task exactly every minute. It doesnt matter whether it starts counting 1 minute fromn the 'first task', or, 'on the miniute (i.e. 00 seconds).

I am currently using the code in the snippet below, but I dont trust this to be accurate. It MUST fire every minute without fail - do if it fired after 61 seconds, then that would be a problem.
Also I dont like the way way the snippet below it constantly looping forever. (there must be an overhead with that)
Howeber, if this snippet below is "OK" then please say so - and don't try to think up other examples.
Thank you

Start Free Trial
1:
2:
3:
4:
5:
for (int i = 0; ; i++)
{
  // Do task here...
  Thread.Sleep(10000);
}
[+][-]05.15.2008 at 07:55AM PDT, ID: 21574303

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 08:21AM PDT, ID: 21574634

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 08:24AM PDT, ID: 21574668

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.15.2008 at 09:54AM PDT, ID: 21575745

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 10:31AM PDT, ID: 21584726

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 10:45AM PDT, ID: 21584868

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.16.2008 at 12:59PM PDT, ID: 21585949

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.19.2008 at 12:09AM PDT, ID: 21595670

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 12:31PM PDT, ID: 21609518

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual C#.Net, .NET, C# Programming Language
Tags: c#
Sign Up Now!
Solution Provided By: FrancineTaylor
Participating Experts: 5
Solution Grade: A
 
 
[+][-]05.20.2008 at 12:52PM PDT, ID: 21609727

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]06.04.2008 at 03:51AM PDT, ID: 21708656

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628