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 13 1509
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.DoE vents() between the iterations, say ever x
iterations.
bye
Rob
Robert Jordan <ro*****@gmx.ne t> 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.DoE vents() 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.DoE vents() can cause nastiness like re-entrancy. To my
mind, Application.DoE vents() 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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi Jon and Robert,
Thanks for the replies. I tried using the Application.DoE vents() 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.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com... Robert Jordan <ro*****@gmx.ne t> 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.DoE vents() 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.DoE vents() can cause nastiness like re-entrancy. To my mind, Application.DoE vents() 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.co m> http://www.pobox.com/~skeet If replying to the group, please do not mail me too
Hi Jon, Robert Jordan <ro*****@gmx.ne t> 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.D oEvents() 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.DoE vents() can cause nastiness like re-entrancy. To my mind, Application.DoE vents() 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.DoE vents().
My mistake was not to mention the threading solution at all.
Thanks
Rob
guy <wi*********@ho tmail.com> wrote: Thanks for the replies. I tried using the Application.DoE vents() 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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Robert Jordan <ro*****@gmx.ne t> 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.DoE vents().
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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
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.D oEvents().
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
Robert Jordan <ro*****@gmx.ne t> 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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 line but not from a
browser. The page does not throw an error but the oShell.Run... portion of
the script doesn't run. Any help would be appreciated. Thanks.
|
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 "c:\inetpub\wwwroot\logasp\getdr.bat > c:\tstlog.txt"
%>
the batch file is as follows:
|
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 programs and executing registry
entries. The majority of my buttons work however, I have come upon a problem.
I need a few of the buttons to run DOS batch files, the batch files in turn
run program installers (specifically windows update runtime .exe...
|
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 based on what I see in the tmp
directory.
Anybody have this working?
<compilation defaultLanguage="vb" debug="true"
batch="true"
|
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
System.Diagnostics.Process.StandardError and
System.Diagnostics.Process.StandardOutput to capture and view the
output and error messages. My web.config file has the following:
<identity impersonate="true" userName="administrator"
password="password" />
| |
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 unwanted break and the text
wraps at the hyphen.
NavigateUrl bound to Eval("file_name","//acqlib/data/{0:c}") launches the
file just fine since there is nothing wrong with the '-' on the linux system
which is the acqlib server.
But binding...
|
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 case it's a question,
i want to popup a messageBox or something, and bring back to the batch file
the result (Yes\No question). I know how to excute the batch file and get all
the Standard output at the end, but i don't know who can i read it line by...
|
by: Matias Surdi |
last post by:
aditya shukla escribió:
Maybe py2exe can help you.
|
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 query, but where do
I go from there?
|
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...
|
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: 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...
|
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();...
|
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: 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
| |