473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

break in batch testing...

guy
Hi,

I'm running a batch test using a C# program. This often takes several hours
to run and iterates over a bunch of parameters (say) 1000 times.

The processor is maxed out during this time.

I'd like to provide a button that cancels the batch test when it is
partially done.

I'm thinking about putting some Wait() or Pause() code in between the
iterations and then setting a flag if a Cancel button is pushed but not sure
if this would work.

What is the standard approach to implementing this sort of thing?

Thanks
Nov 16 '05 #1
13 1479
Hi,
Hi,

I'm running a batch test using a C# program. This often takes several hours
to run and iterates over a bunch of parameters (say) 1000 times.

The processor is maxed out during this time.

I'd like to provide a button that cancels the batch test when it is
partially done.

I'm thinking about putting some Wait() or Pause() code in between the
iterations and then setting a flag if a Cancel button is pushed but not sure
if this would work.

What is the standard approach to implementing this sort of thing?


Disable all UI controls but the cancel button. Call
Application.DoEvents() between the iterations, say ever x
iterations.

bye
Rob
Nov 16 '05 #2
Robert Jordan <ro*****@gmx.net> wrote:
I'm running a batch test using a C# program. This often takes several hours
to run and iterates over a bunch of parameters (say) 1000 times.

The processor is maxed out during this time.

I'd like to provide a button that cancels the batch test when it is
partially done.

I'm thinking about putting some Wait() or Pause() code in between the
iterations and then setting a flag if a Cancel button is pushed but not sure
if this would work.

What is the standard approach to implementing this sort of thing?


Disable all UI controls but the cancel button. Call
Application.DoEvents() between the iterations, say ever x
iterations.


I disagree with this, apart from disabling all UI controls. It is
better to run the iterations on a separate thread and test for a flag.
Application.DoEvents() can cause nastiness like re-entrancy. To my
mind, Application.DoEvents() is basically a throw-back to VB not having
"proper" threading for a long time, and should be avoided in almost all
situations.

UIs should be kept responsive by keeping their message pump threads
idle for as much of the time as possible.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
guy
Hi Jon and Robert,

Thanks for the replies. I tried using the Application.DoEvents() suggested
by Robert but not the disable UI and it works a treat.

Jon, could you elaborate on not using this.

I'm basically popping up a "progress" dialog which reports time elapsed and
% progress through the batch test etc. and there is a Cancel button on this
dialog. The main code that popped up this progress dialog checks a flag in
this class and if set stops the batch testing. This flag is set by clicking
the Cancel button. I find that if I don't inlcude the .DoEvents() call in
the check to the flag then clicking on the Cancel button does not set the
flag...

Thanks
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
Robert Jordan <ro*****@gmx.net> wrote:
> I'm running a batch test using a C# program. This often takes several
> hours
> to run and iterates over a bunch of parameters (say) 1000 times.
>
> The processor is maxed out during this time.
>
> I'd like to provide a button that cancels the batch test when it is
> partially done.
>
> I'm thinking about putting some Wait() or Pause() code in between the
> iterations and then setting a flag if a Cancel button is pushed but not
> sure
> if this would work.
>
> What is the standard approach to implementing this sort of thing?


Disable all UI controls but the cancel button. Call
Application.DoEvents() between the iterations, say ever x
iterations.


I disagree with this, apart from disabling all UI controls. It is
better to run the iterations on a separate thread and test for a flag.
Application.DoEvents() can cause nastiness like re-entrancy. To my
mind, Application.DoEvents() is basically a throw-back to VB not having
"proper" threading for a long time, and should be avoided in almost all
situations.

UIs should be kept responsive by keeping their message pump threads
idle for as much of the time as possible.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #4
Hi Jon,
Robert Jordan <ro*****@gmx.net> wrote:
I'm running a batch test using a C# program. This often takes several hours
to run and iterates over a bunch of parameters (say) 1000 times.

The processor is maxed out during this time.

I'd like to provide a button that cancels the batch test when it is
partially done.

I'm thinking about putting some Wait() or Pause() code in between the
iterations and then setting a flag if a Cancel button is pushed but not sure
if this would work.

What is the standard approach to implementing this sort of thing?
Disable all UI controls but the cancel button. Call
Application.DoEvents() between the iterations, say ever x
iterations.

I disagree with this, apart from disabling all UI controls. It is
better to run the iterations on a separate thread and test for a flag.
Application.DoEvents() can cause nastiness like re-entrancy. To my
mind, Application.DoEvents() is basically a throw-back to VB not having
"proper" threading for a long time, and should be avoided in almost all
situations.

UIs should be kept responsive by keeping their message pump threads
idle for as much of the time as possible.


Well, it depends on the target "audience" of the application.
I read:
I'm running a batch test using a C# program. This often takes several
hours to run and iterates over a bunch of parameters (say) 1000 times.


The main purpose of the app appears to be the batch job and not
a fancy and responsible UI. That's the reason why I recommended
Application.DoEvents().

My mistake was not to mention the threading solution at all.

Thanks
Rob
Nov 16 '05 #5
guy <wi*********@hotmail.com> wrote:
Thanks for the replies. I tried using the Application.DoEvents() suggested
by Robert but not the disable UI and it works a treat.

Jon, could you elaborate on not using this.

I'm basically popping up a "progress" dialog which reports time elapsed and
% progress through the batch test etc. and there is a Cancel button on this
dialog. The main code that popped up this progress dialog checks a flag in
this class and if set stops the batch testing. This flag is set by clicking
the Cancel button. I find that if I don't inlcude the .DoEvents() call in
the check to the flag then clicking on the Cancel button does not set the
flag...


Sure - because presumably you're doing all your processing on the UI
thread, which is a bad idea to start with.

I suggest you read my tutorial on threads:

http://www.pobox.com/~skeet/csharp/threads/

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Robert Jordan <ro*****@gmx.net> wrote:
UIs should be kept responsive by keeping their message pump threads
idle for as much of the time as possible.


Well, it depends on the target "audience" of the application.
I read:
> I'm running a batch test using a C# program. This often takes several
> hours to run and iterates over a bunch of parameters (say) 1000 times.


The main purpose of the app appears to be the batch job and not
a fancy and responsible UI. That's the reason why I recommended
Application.DoEvents().

My mistake was not to mention the threading solution at all.


While I agree that a UI for batch processing doesn't need to be fancy,
I disagree about responsible. A UI which is written properly to start
with can easily be extended to provide more feedback etc. No guesswork
is required as to when to call DoEvents. Also, learning just one way of
"doing it right" as regards long-running tasks and UIs is better (IMO)
than learning the "quick and dirty" way and then later learning the
"proper" way (using worker threads).

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #7
Hi Jon,

The main purpose of the app appears to be the batch job and not
a fancy and responsible UI. That's the reason why I recommended
Application.DoEvents().

My mistake was not to mention the threading solution at all.

While I agree that a UI for batch processing doesn't need to be fancy,
I disagree about responsible. A UI which is written properly to start
with can easily be extended to provide more feedback etc. No guesswork
is required as to when to call DoEvents. Also, learning just one way of
"doing it right" as regards long-running tasks and UIs is better (IMO)
than learning the "quick and dirty" way and then later learning the
"proper" way (using worker threads).


If one recommends threading in conjuction with UI, then it's just
a matter of time until the next question about async UI access problems
will be placed, if ever detected and recognized as such.
As you know, that kind of problem can be much subtle then DoEvents.

So what's the best approach to teach that in a newsgroup?
A full blown monologue about Control.Invoke or ignoring it
at all?

Thanks
Rob
Nov 16 '05 #8
Robert Jordan <ro*****@gmx.net> wrote:
While I agree that a UI for batch processing doesn't need to be fancy,
I disagree about responsible. A UI which is written properly to start
with can easily be extended to provide more feedback etc. No guesswork
is required as to when to call DoEvents. Also, learning just one way of
"doing it right" as regards long-running tasks and UIs is better (IMO)
than learning the "quick and dirty" way and then later learning the
"proper" way (using worker threads).
If one recommends threading in conjuction with UI, then it's just
a matter of time until the next question about async UI access problems
will be placed, if ever detected and recognized as such.
As you know, that kind of problem can be much subtle then DoEvents.


"More subtle" is a tough one to call - both are incredibly nasty if
they don't crop up regularly, but I find the ones due to async calling
are easier to avoid when you know about them.

(Fortunately Avalon is going to make things much simpler - if you call
something on the wrong thread, you'll get an exception immediately.)
So what's the best approach to teach that in a newsgroup?
A full blown monologue about Control.Invoke or ignoring it
at all?


Certainly don't ignore it - I point people to my article on threading,
written precisely for the purpose of not having to write the same thing
in several posts :)

http://www.pobox.com/~skeet/csharp/threads

and for Windows Forms programming in particular
http://www.pobox.com/~skeet/csharp/t...winforms.shtml

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #9
Hi Jon,
So what's the best approach to teach that in a newsgroup?
A full blown monologue about Control.Invoke or ignoring it
at all?

Certainly don't ignore it - I point people to my article on threading,
written precisely for the purpose of not having to write the same thing
in several posts :)

http://www.pobox.com/~skeet/csharp/threads

and for Windows Forms programming in particular
http://www.pobox.com/~skeet/csharp/t...winforms.shtml


Thanks a lot!
Rob
Nov 16 '05 #10
guy
Thanks to both of you.

I've implemented a seperate thread with a control form that allows
interruption of the batch job. This has also had the side effect of allowing
me to perform multiple tests at the same time - a pleasant side effect I
wasn't expecting :)

I know about these technicologies (threading etc.) and have used them on
other OS's and with other languages but often need a nudge to use them in a
new language/environment.

Thanks.

"Robert Jordan" <ro*****@gmx.net> wrote in message
news:cl*************@news.t-online.com...
Hi Jon,
So what's the best approach to teach that in a newsgroup?
A full blown monologue about Control.Invoke or ignoring it
at all?

Certainly don't ignore it - I point people to my article on threading,
written precisely for the purpose of not having to write the same thing
in several posts :)

http://www.pobox.com/~skeet/csharp/threads

and for Windows Forms programming in particular
http://www.pobox.com/~skeet/csharp/t...winforms.shtml


Thanks a lot!
Rob

Nov 16 '05 #11
guy
Jon,

Thanks for your help with the threading etc.

I've read through your stuff on the web but there's one type of lock that I
don't quite get but need to use.

In the main thread I wish to set a lock which the main thread itself can't
re-lock and the thread that i'm spawning will hold the lock and the main
thread will wait on that lock until the spawned thread has completed.

What is the best type of lock/mutex/semaphore to use for this.

So basically the main thread is in a loop and I want the loop to procede to
the next item once the spawned thread is complete. So I was thinking of
locking an object in the main thread and passing that to the spawned thread
which unlocks the object when it completes (or in the finally clause if
exception thrown).

What do you think of this idea?

Thanks


Nov 16 '05 #12
Hi guy:

It sounds as if you are looking for an AutoResetEvent so the worker
therad can signal when it completes:

http://www.yoda.arachsys.com/csharp/...thandles.shtml

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 20 Oct 2004 03:15:07 -0400, "guy" <wi*********@hotmail.com>
wrote:
Jon,

Thanks for your help with the threading etc.

I've read through your stuff on the web but there's one type of lock that I
don't quite get but need to use.

In the main thread I wish to set a lock which the main thread itself can't
re-lock and the thread that i'm spawning will hold the lock and the main
thread will wait on that lock until the spawned thread has completed.

What is the best type of lock/mutex/semaphore to use for this.

So basically the main thread is in a loop and I want the loop to procede to
the next item once the spawned thread is complete. So I was thinking of
locking an object in the main thread and passing that to the spawned thread
which unlocks the object when it completes (or in the finally clause if
exception thrown).

What do you think of this idea?

Thanks


Nov 16 '05 #13
guy
Thanks Scott - that pointed me in the right direction.

In the end I wrote a thread management class which I'm going to attach a GUI
to in a short while. Basically it is reminiscent of the job batch handler on
the old mainframes. So I create a number of threads but only allow a certain
number to be running at one time and so the management class itself has 2
threads running: 1. That monitors the number of jobs (threads) running and
2. One that does cleanup and maintenance of the thread pool.

Now you're going to tell me that this thread management class already exists
in .NET aren't you? And that I've just reinvented the wheel... :)

I've based my thread management class on ArrayList.

Thanks
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:s7********************************@4ax.com...
Hi guy:

It sounds as if you are looking for an AutoResetEvent so the worker
therad can signal when it completes:

http://www.yoda.arachsys.com/csharp/...thandles.shtml

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Wed, 20 Oct 2004 03:15:07 -0400, "guy" <wi*********@hotmail.com>
wrote:
Jon,

Thanks for your help with the threading etc.

I've read through your stuff on the web but there's one type of lock that
I
don't quite get but need to use.

In the main thread I wish to set a lock which the main thread itself can't
re-lock and the thread that i'm spawning will hold the lock and the main
thread will wait on that lock until the spawned thread has completed.

What is the best type of lock/mutex/semaphore to use for this.

So basically the main thread is in a loop and I want the loop to procede
to
the next item once the spawned thread is complete. So I was thinking of
locking an object in the main thread and passing that to the spawned
thread
which unlocks the object when it completes (or in the finally clause if
exception thrown).

What do you think of this idea?

Thanks

Nov 16 '05 #14

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

Similar topics

14
by: Mark C. | last post by:
I'm trying to call a batch file that I've built using the FileSystemObject and CreateObject("Wscript.Shell"), oShell.Run... in an asp script. Naturally, I can get the script to work from a command...
9
by: Doug at SAU | last post by:
I need to run a batch file on a remote machine from an ASP page. I dummied up a test ASP page as follows: <% Set WshShell = Server.CreateObject("Wscript.Shell") wshshell.run...
6
by: Charles Neitzel | last post by:
I'm trying to write a windows application in C# (Using Microsoft Visual C# 2005 Express) that is nothing more than a simple UI with buttons on it. The buttons do various things like running...
1
by: Rick | last post by:
I am testing out the compilation options in web.config to batch-compile each directory. It doesn't appear to behaving as expected. It looks like there is not any batch compiling happening at all...
0
by: Elroyskimms | last post by:
I need to execute a batch file via ASP.Net. In my VB.Net code, I'm using System.Diagnostics.Process to call the batch file and its appropriate command line arguments. I'm using...
3
by: Joe Stateson | last post by:
I have a template field that contains filenames that are (or can be) on a unix system. The hypen (and others) is a valid filename character in unix. When I display the name of the file I get an...
14
by: =?Utf-8?B?R2lkaQ==?= | last post by:
Hi, In my windows applicationm, i need to excute a batch file. this batch file throws some text and questions to the screen, i need to catch the standard Output, check if it's a question, in...
5
by: Matias Surdi | last post by:
aditya shukla escribió: Maybe py2exe can help you.
5
by: slickdock | last post by:
I need to break my query into 3 groups: First 60 records (records 1-60) Next 60 records (records 61-121) Next 60 records (records 122-182) Of course I could use top values 60 for the first...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
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,...

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.