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? 19 86688
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?
"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
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
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
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
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
"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.
"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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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...
|
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...
|
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...
|
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!
|
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)
| |
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
|
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
|
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.
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |