Pausing a process without holding OS

  • Thread starter Thread starter John
  • Start date Start date
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
 
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
 
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
 
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
 
Back
Top