473,854 Members | 1,584 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Creating a Pause in Execution

What's a nice way to create a non-blocking pause in execution?

Will I need to use some kind of timer for this, or is there a nicer
way?
Nov 15 '05 #1
19 86699
int pauseTime = 2000;
System.Threadin g.Thread.Sleep( pauseTime);

"C# Learner" <cs****@learner .here> wrote in message
news:8b******** *************** *********@4ax.c om...
What's a nice way to create a non-blocking pause in execution?

Will I need to use some kind of timer for this, or is there a nicer
way?

Nov 15 '05 #2
"Vadym Stetsyak" <pd****@ukr.net > wrote:
"C# Learner" <cs****@learner .here> wrote in message
news:8b******* *************** **********@4ax. com...
What's a nice way to create a non-blocking pause in execution?

Will I need to use some kind of timer for this, or is there a nicer
way?


int pauseTime = 2000;
System.Threadi ng.Thread.Sleep (pauseTime);


Hi Vadym, thanks for your quick response.

The problem with that is - it blocks the current (GUI) thread. I'm
looking for something that will do this without blocking the current
thread.

Regards
Nov 15 '05 #3
C# Learner <cs****@learner .here> wrote:
The problem with that is - it blocks the current (GUI) thread. I'm
looking for something that will do this without blocking the current
thread.


What *exactly* are you trying to pause then? If it's another thread,
just make that other thread sleep instead.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
In article <fa************ *************** *****@4ax.com>,
cs****@learner. here says...
"Vadym Stetsyak" <pd****@ukr.net > wrote:
"C# Learner" <cs****@learner .here> wrote in message
news:8b******* *************** **********@4ax. com...
What's a nice way to create a non-blocking pause in execution?

Will I need to use some kind of timer for this, or is there a nicer
way?


int pauseTime = 2000;
System.Threadi ng.Thread.Sleep (pauseTime);


Hi Vadym, thanks for your quick response.

The problem with that is - it blocks the current (GUI) thread. I'm
looking for something that will do this without blocking the current
thread.

Regards


You'll have to use a separate thread for the GUI and the thing you want
to pause then use Vadym's solution. At first I wasn't sure what you
meant by non-blocking, in relation to other programs or within your
program,

--
Thanks
Mark mm
Nov 15 '05 #5
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
C# Learner <cs****@learner .here> wrote:
The problem with that is - it blocks the current (GUI) thread. I'm
looking for something that will do this without blocking the current
thread.


What *exactly* are you trying to pause then? If it's another thread,
just make that other thread sleep instead.


Let me clarify...

My GUI app has only a single thread. I would like to create a pause
in execution without blocking this single thread.

Right now I'm using a timer to do this:

private void Foo()
{
delayTimer.Star t();
}

private void delayTimer_Tick (object sender, System.EventArg s e)
{
delayTimer.Stop ();
DoSomething();
}

The effect here is that DoSomething() is called after a short delay.

Now, this works fine, but I was wondering if there's a nicer method of
doing this.

Thanks
Nov 15 '05 #6
C# Learner <cs****@learner .here> wrote:
Let me clarify...

My GUI app has only a single thread. I would like to create a pause
in execution without blocking this single thread.
I still don't understand what you really mean by a "pause" then. A
pause has to occur in *some* thread...
Right now I'm using a timer to do this:

private void Foo()
{
delayTimer.Star t();
}

private void delayTimer_Tick (object sender, System.EventArg s e)
{
delayTimer.Stop ();
DoSomething();
}

The effect here is that DoSomething() is called after a short delay.

Now, this works fine, but I was wondering if there's a nicer method of
doing this.


That sounds like it's basically another thread (a threadpool thread)
which is then calling back to your event handler. (I don't know whether
it's a System.Windows. Forms.Timer or a System.Threadin g.Timer though.)

That's basically what you need though - it's not what I'd describe as a
pause though, so much as scheduling something to occur at some point in
the future. You're not actually *pausing* anything, as far as I can
see.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #7
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
C# Learner <cs****@learner .here> wrote:
The problem with that is - it blocks the current (GUI) thread. I'm
looking for something that will do this without blocking the current
thread.


What *exactly* are you trying to pause then? If it's another thread,
just make that other thread sleep instead.


I think he wants to make the main thread to go to sleep for a number of
seconds yet wake up and service GUI events as they occur, then get back to
sleep at the point it was initially laid to bed and wait for the remaining
time to be waken up by the alarm set when it was first put to sleep. Just
getting a grip on threads I guess :-).

I agree, he should explain the problem, someone will post a solution and
threads will make more sense to him.

Coming from a non-threaded background this is the way you think, I can
relate to that. In the old days we used to keep our system responsive by
doing our "background processing" on the one main thread in a loop, calling
Application.Pro cessMessages or the equivalent of that every x iterations so
the user could abort the operation by pressing a button that raised a flag
that would make the code leave the loop.

Martin.
Nov 15 '05 #8
"Martin Maat [EBL]" <du***@somewher e.nl> wrote:
I think he wants to make the main thread to go to sleep for a number of
seconds yet wake up and service GUI events as they occur, then get back to
sleep at the point it was initially laid to bed and wait for the remaining
time to be waken up by the alarm set when it was first put to sleep. Just
getting a grip on threads I guess :-).

I agree, he should explain the problem, someone will post a solution and
threads will make more sense to him.
I'm just thinking to make a simple pause without going to the extra
effort of writing and maintaining a seperate thread. Sure, I know how
this could be implemented with an extra thread, but I really want a
simple and neat solution here.

Never mind - I'll stick with the timer.
Coming from a non-threaded background this is the way you think, I can
relate to that. In the old days we used to keep our system responsive by
doing our "background processing" on the one main thread in a loop, calling
Application.Pr ocessMessages or the equivalent of that every x iterations so
the user could abort the operation by pressing a button that raised a flag
that would make the code leave the loop.
I've seen a lot of recent code that does this, believe it or not!
It's almost an abuse of the CPU.
Martin.

Nov 15 '05 #9
C# Learner <cs****@learner .here> wrote:
I'm just thinking to make a simple pause without going to the extra
effort of writing and maintaining a seperate thread. Sure, I know how
this could be implemented with an extra thread, but I really want a
simple and neat solution here.


Okay, so "pause" was a bad choice of word here. I'm thinking of
"pause" from a high-level -- from the user's perspective.
Nov 15 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7624
by: Dr. Know | last post by:
I am working on an ASP page that writes to several databases, ranging from MDBs to x-base. One of the tasks involves using an existing highest value from the DB and incrementing it before inserting a new record. I am using Application.Lock and .Unlock together with an application variable to negotiate access to the DB routine to one session (user) at a time. This is to ensure that the ID numbers are cleanly incremented, and that no...
3
2926
by: jdph40 | last post by:
In Access 2002, I designed a simple database for our Safety department to enter results of a survey. There are 41 true/false statements. I have a main form called frmSurvey with a subform called sbfrmAnswers. I put an option group (optAnswers) on the subform with buttons for true or false. To speed entry of the results of the 350+ surveys we've collected, I put the following code in the AfterUpdate event of the option group: With...
8
36484
by: Wim | last post by:
My GUI application starts a process (a console program) when the user hits Play. I would like to add an option to pause that process. The code I've added to detect if the user hit pause/unpause seems to work. But I have no clue how to pause/suspend the process. As far as I can see the Process class doesn't offer anything for this. So it's probably the thread the process is running on that should be suspended or put to sleep. But just...
4
2931
by: Fred Nelson | last post by:
Hi: I'm trying to write a routine that will permit my VB.NET program to pause execution for five minutes and try a task again if there is a failure. After a set number of tries it should return a failure notification. I know how to do everything except make it hibernate for five minutes - if anyone knows how to do this I would GREATLY apprecaite it!
1
1802
by: Noggon | last post by:
Maybe I'm stupid, but I can't find out what is wrong, can anyone help? I keep getting the function first as being undefined for some reason I don't get. I'm trying to use setTimeout() to pause execution so that an image in my web page is switched every two seconds for another. switch(pic_catagory)
18
1807
by: Frank | last post by:
I'm using Sleep(100) and that works OK. However, it would be better if my app continued to receive and process keyboard messages. How can I pause the execution of code in one routine while letting the app respond to keyboard input? Thanks
0
1460
by: steveyjg | last post by:
I'm trying to call a function that will pause execution for 30 seconds and have a counter timer counting to 30 seconds during this pause. When the counter hits 30 execution of the program will continue. So far I have tried: Public Function timeDelay() timerCounter = 0 'global variable Timer1.Enabled = True End Function
1
2811
by: desktop | last post by:
Is there someway to pause the execution of a program? I have a large while loop and before it gets started I would like to pause the program so I can see the output before it gets overwritten by the loop.
2
6152
by: npcarp | last post by:
Is this hard? I am introducing Python to my students and want to make a simple, interactive program that will, while it's running, 'listen' for any keyboard events. That is, I don't want to include an 'input' statement - that would pause execution till someone answered. I just want it to keep running, say, printing an 'a' on the screen every 10 seconds, until the user types a 'b'. Then printing a 'b' every 10 seconds till the user types in...
0
9901
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11031
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10685
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7082
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5942
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4563
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4162
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.