473,838 Members | 1,637 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
19 86695
> My GUI app has only a single thread. I would like to create a pause
in execution without blocking this single thread.


If we take this literally it is impossible, contradictary in itself. But if
lagged execution of a command is really what you are after your solution is
effective, efficient and elegant.

The only application I can think of is an OS/2 or Linux GUI simulator.
"Sluggish responsiveness for Windows". Might that be what you are making?
:-).

Martin.
Nov 15 '05 #11
"Martin Maat [EBL]" <du***@somewher e.nl> wrote:
My GUI app has only a single thread. I would like to create a pause
in execution without blocking this single thread.
If we take this literally it is impossible, contradictary in itself. But if
lagged execution of a command is really what you are after your solution is
effective, efficient and elegant.

The only application I can think of is an OS/2 or Linux GUI simulator.
"Sluggish responsiveness for Windows". Might that be what you are making?
:-).


I can't speak for OS/2 'coz I've never used it, but I find GNU/Linux
faster in general (on this box) that Win XP.

Anyway...

I'm making a simple game in which the human makes his/her move, then
the computer opponent makes "his/her" move after a slight delay.
Martin.


Nov 15 '05 #12
Jon Skeet [C# MVP] <sk***@pobox.co m> wrote:
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.)
It's a System.Windows. Forms.Timer timer. Hmm... I might look into
using one of the other two timers, as this one is eligable for garbage
collection when it's disabled. Can't be good for this app - it's
starting a stopping a lot.
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.


Nov 15 '05 #13
C# Learner <cs****@learner .here> wrote:
It's a System.Windows. Forms.Timer timer. Hmm... I might look into
using one of the other two timers, as this one is eligable for garbage
collection when it's disabled.


I'm presuming that means the Win32 timer this object wraps around.
Nov 15 '05 #14
> It's a System.Windows. Forms.Timer timer. Hmm... I might look into
using one of the other two timers, as this one is eligable for garbage
collection when it's disabled. Can't be good for this app - it's
starting a stopping a lot.


As long as your timer component does not run out of scope it will not be
garbage collected, I see no need to worry there.

Furthermore, I am not absolutely sure about how this particular timer
component is implemented but its behavior suggests it is the good old 18.2
times a second interupt based timer. I do not expect a separate thread to be
living in the timer component. Every 0.054 seconds your timer gets a chance
to check if the interval has elapsed and if it has the component will post a
message to your form which is handled by your main thread like any other UI
event and dispatched to your timer event handler. In a GUI application you
cannot get more efficient than that.

Martin.
Nov 15 '05 #15
> >The only application I can think of is an OS/2 or Linux GUI simulator.
"Sluggish responsiveness for Windows". Might that be what you are making?
:-).
I can't speak for OS/2 'coz I've never used it, but I find GNU/Linux
faster in general (on this box) that Win XP.

I installed Mandrake with KDE and it looks very nice, I don't want
to bash it in any way but I found it considerably less snappy than
Windows XP on the same box.
Anyway...
Indeed.
I'm making a simple game in which the human makes his/her move, then
the computer opponent makes "his/her" move after a slight delay.


I would use a timer in the same manner, seems like the way to go, no need to
mess with threads. I might add that if the computer's thinking is (or might
get as the app evolves) a heavy task that takes a bit of processing time,
you will need that thread anyway for determining the computer's next move.
And then I would say it would be better to start working on the response
right after the human made his move and then either make the computed move
straight away or, if the result would be available before the minimum lapse,
sleep until the minimum lapse has passed. That way you would not waste any
time.

Martin.
Nov 15 '05 #16
"Martin Maat [EBL]" <du***@somewher e.nl> wrote:
It's a System.Windows. Forms.Timer timer. Hmm... I might look into
using one of the other two timers, as this one is eligable for garbage
collection when it's disabled. Can't be good for this app - it's
starting a stopping a lot.
As long as your timer component does not run out of scope it will not be
garbage collected, I see no need to worry there.


I wouldn't have been concernced here, but then I read this:

http://msdn.microsoft.com/library/de...thodsTopic.asp

"A timer that is disabled is subject to garbage collection."

I wonder what this means exactly.
Furthermore, I am not absolutely sure about how this particular timer
component is implemented but its behavior suggests it is the good old 18.2
times a second interupt based timer. I do not expect a separate thread to be
living in the timer component. Every 0.054 seconds your timer gets a chance
to check if the interval has elapsed and if it has the component will post a
message to your form which is handled by your main thread like any other UI
event and dispatched to your timer event handler. In a GUI application you
cannot get more efficient than that.
I expect it to work like this too.
Martin.


Regards
Nov 15 '05 #17
"Martin Maat [EBL]" <du***@somewher e.nl> wrote:
>The only application I can think of is an OS/2 or Linux GUI simulator.
>"Sluggish responsiveness for Windows". Might that be what you are making?
>:-).
I can't speak for OS/2 'coz I've never used it, but I find GNU/Linux
faster in general (on this box) that Win XP.

I installed Mandrake with KDE and it looks very nice, I don't want
to bash it in any way but I found it considerably less snappy than
Windows XP on the same box.


I'm a Mandrake user myself.

:-)
Anyway...


Indeed.
I'm making a simple game in which the human makes his/her move, then
the computer opponent makes "his/her" move after a slight delay.


I would use a timer in the same manner, seems like the way to go, no need to
mess with threads. I might add that if the computer's thinking is (or might
get as the app evolves) a heavy task that takes a bit of processing time,
you will need that thread anyway for determining the computer's next move.
And then I would say it would be better to start working on the response
right after the human made his move and then either make the computed move
straight away or, if the result would be available before the minimum lapse,
sleep until the minimum lapse has passed. That way you would not waste any
time.


Well, in this app, the computer's thinking is so simple that its move
would be made more or less *immediately* after the human's move, so I
don't have to concern myself with the above.
Martin.


Thanks Martin.
Nov 15 '05 #18
> >As long as your timer component does not run out of scope it will not be
garbage collected, I see no need to worry there.
I wouldn't have been concernced here, but then I read this:

http://msdn.microsoft.com/library/de...thodsTopic.asp
"A timer that is disabled is subject to garbage collection."
I don't find that statement behind the link. The same message in different
words is here though:

http://msdn.microsoft.com/library/de...abledtopic.asp

"The timer is not subject to garbage collection when the value is true."
I wonder what this means exactly.


I would think this simply means there is some lazy initialization and
agressive cleanup going on within the timer object which is after all a
wrapper around a system timer. Since system timers are a limited resource
and you are not really using the system timer while the component's Enabled
property is set to false it can be released. As soon as you enable it again
you will get a new one on the fly. To you as a client it makes no
difference. I cannot imagine that the wrapping timer component you have on
your form will be spontaniously garbage collected while you are holding a
reference to it. The choice of words in the ducumentation may be
unfortunate.

I am making this up though, I too am getting curious about the true meaning
of the statement.

Martin.
Nov 15 '05 #19
"Martin Maat [EBL]" <du***@somewher e.nl> wrote:
>As long as your timer component does not run out of scope it will not be
>garbage collected, I see no need to worry there.
I wouldn't have been concernced here, but then I read this:

http://msdn.microsoft.com/library/de...thodsTopic.asp

"A timer that is disabled is subject to garbage collection."


I don't find that statement behind the link. The same message in different
words is here though:

http://msdn.microsoft.com/library/de...abledtopic.asp

"The timer is not subject to garbage collection when the value is true."


Sorry, the correct link should have been:

http://msdn.microsoft.com/library/en...asp?frame=true
I wonder what this means exactly.


I would think this simply means there is some lazy initialization and
agressive cleanup going on within the timer object which is after all a
wrapper around a system timer. Since system timers are a limited resource
and you are not really using the system timer while the component's Enabled
property is set to false it can be released. As soon as you enable it again
you will get a new one on the fly. To you as a client it makes no
difference. I cannot imagine that the wrapping timer component you have on
your form will be spontaniously garbage collected while you are holding a
reference to it. The choice of words in the ducumentation may be
unfortunate.

I am making this up though, I too am getting curious about the true meaning
of the statement.


The bit that throws me is that it says that the "timer" is subject to
garbage collection when disabled. Ambiguous...
Martin.


Thanks for your thoughts!
Nov 15 '05 #20

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

Similar topics

7
7622
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
2925
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
36472
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
2930
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
1805
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
1459
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
6150
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
9854
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
9696
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,...
1
10645
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9425
agi2029
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...
1
7827
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
7015
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
5681
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...
0
5865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4482
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 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.