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]" <skeet@pobox.com> wrote in message
news:MPG.1bdd93da4fd99e0098b716@msnews.microsoft.c om...[color=blue]
> Robert Jordan <robertj@gmx.net> wrote:[color=green][color=darkred]
>> > 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?[/color]
>>
>> Disable all UI controls but the cancel button. Call
>> Application.DoEvents() between the iterations, say ever x
>> iterations.[/color]
>
> 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 - <skeet@pobox.com>
>
http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too[/color]