Hello friends,

I had done some questions regarding function call.

I had done an console application that can run a particular set of code every minute.

For that i used

System.Threading.Thread.Sleep(60000);

That worked well too.

But now i stuck in another problem.

Now I dont wanna use the above code.Because of the reason the thread.sleep() makes the entire application to sleep for a minute. But I am having a code that must be executed in the mean time.

Any suggestions or help?

TIA...

You can use a Timer which can be set to execute a method at certain time intervals. MSDN Link

@Ketsuekiame,

Fine. But I can use it as an last resource.

because i am new to console application.

I am having little doubts regarding basics of c#.

Before that, let me explain you a scenario.

My code will be like

void main()
{

DateTime a=DateTime.Now;
DateTime b=DateTime.Now.AddMinutes(1);
//

Codes that needs to be executed all the time.


//

int Difference = (b - a).Minutes;
if(timedifference=1)
{

//    

call function i.e., code that has to be executed for every minute

//
}
}

The above is my coding procedure which i have planed so far.My doubt is that
1)whether the condition is checked frequently or only once?
2)if the entire code is executed again and again does the datetime values are initiated every time?

The questions may be childish... But I am noob when it comes for console app..

Well.. the condition is checked frequently...

IF the condition is checked frequently, then the decalration will also be done frequently...

Your condition is checked only once when you start the application. You'd need a while loop. However, the Timers are built specifically to do this kind of work and they'r every easy to implement.

This is a little tutorial on how to use a Timer.

Fine... That leaves me without option :-). I will try and intimate you guys shortly...

Thanks for your response.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.