Pausing a process without holding OS

J

John

Hi

I need to add pauses in-between processes in my app to give time to other
users/processes on the network. Is there a way to pass control to OS for a
specified time (say 15 seconds) to delay my app but at the same time not
blocking OS's processor cycles?

Thanks

Regards
 
A

Armin Zingler

John said:
Hi

I need to add pauses in-between processes in my app to give time to
other users/processes on the network. Is there a way to pass control
to OS for a specified time (say 15 seconds) to delay my app but at
the same time not blocking OS's processor cycles?

Threading.Thread.Sleep(15000)



If the thread has a UI, it's better not to Sleep because it locks the UI.
- Instead you should set a Timer and do whatever in 15 seconds
- Or, do whatever has to be done in another thread (including Sleep). Then I
also suggest not to sleep for 15 seconds but only max 1 second (for example)
in a loop in order to be able to react to cancel requests.


Armin
 
S

SurturZ

Application.DoEvents() is probably the easiest way. You need to disable all
your controls so you don't get cascading events.

For example,
Me.Enabled = False
Application.DoEvents()
Me.Enabled = True
 
A

Armin Zingler

SurturZ said:
Application.DoEvents() is probably the easiest way. You need to
disable all your controls so you don't get cascading events.

For example,
Me.Enabled = False
Application.DoEvents()
Me.Enabled = True


I wouldn't recommend DoEvents. I gave the reasons some weeks ago (can be
searched for). In (very) short: If I want to do two things at the same time,
I use two Threads. That's what they are made for. If I have two threads,
there is no reason to use DoEvents.


Armin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top