Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Closed Points: 75 Time: 05:13 - May 01, 2007  

dustPuppy

how can I cause my application to wait and then resume after a while in .net?

I need my program to perform a routine and then wait for 5 minutes before doing it again.
I'm using .net 2.0 (C#) and I need the application to respond as normal, i.e. if the user drags it around etc., but it should not consume too much cpu while waiting.
how do I best do that?

Categories

Answer Discussion
Tutorials

 

nidhi

Date:: May 01, 2007

Time:: 11:32

Have u considered using the Timer class?

eg
Timer myTimer = new Timer();
myTimer.Elapsed += new ElapsedEventHandler( DisplayTimeEvent );
myTimer.Interval = 1000;
myTimer.Start();

'do stuff


and the function that has been defined above can be coded like this

public static void DisplayTimeEvent( object source, ElapsedEventArgs e )
{
Console.Write("\r{0}", DateTime.Now);
}



Now Im thinking a infinite loop but not sure how you track mouse movements or keypresses

nidhi

Date:: May 01, 2007

Time:: 11:35

r u using windowsforms? I think there is a mousemove event u can capture - cant remember

But I got this link which may help you capture mouse movements, so that u can come out the loop that u have after your timer definiton, hope this helps http://www.codeproject.com/csharp/Global...

PeterNZ

Date:: May 01, 2007

Time:: 15:17

Create a new thread, run the routine on the new thread and use sleep to pause the thread for 5 minutes.

This leaves your form which runs on the main thread responsive without having to do mouse event trapping etc.

If you need to capture an event from your routine on the separate thread,use callback functions.

Here are a couple of links and tutorials:
http://www.c-sharpcorner.com/UploadFile/...
http://www.codersource.net/csharp_tutori...
http://www.yoda.arachsys.com/csharp/thre...
http://www.c-sharpcorner.com/UploadFile/...

Hope this helped

Cheers

Peter

dustPuppy

Date:: Jun 04, 2007

Time:: 01:37

thanks and sorry for not getting back to this before.
Peter, your solution was the one I was looking for...

sarkapally1

Date:: Nov 19, 2007

Time:: 17:27

You can use the following to make the system to sleep for certain time

Threading.Thread.Sleep(Time)

here time is in milli seconds

If you want some thing like implementing progress bar while retrieving data let me know
- Rajavardhan Sarkapally

Question Answered

This question has been closed, and points have been rewarded to the following experts:


nidhi: 10
PeterNZ: 65

You're welcome however to comment or give additional information or if you wish, you have the ability to write a Tutorial in the Tutorial Area.

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

No tutorials have been submitted yet. Want to be the first?

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10279

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es