Re: Button to interupt a foreach loop?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Mike (vimakefile_at_yahoo.com)
Date: 07/28/04


Date: Wed, 28 Jul 2004 16:16:26 -0700


(1) You could do the work on another thread (Also see Control.Invoke to
update the GUI from the other thread.
For a start, I just googled this:
http://samples.gotdotnet.com/quickstart/howto/doc/WinForms/WinFormsThreadMarshalling.aspx

(2) Simpler - I think there's a DoEvents (Under Application?) -- call this
in your loop, a la down-home VB-style cookin'.

m

"Dave Spencer" <spencerde@fuse.net> wrote in message
news:C4WNc.815$LT1.230@fe37.usenetserver.com...
> Hi all,
>
> New to this group and to C# in general (experienced in MFC). Anyway I
have
> a ListView and a foreach loop that is doing something to each item in the
> list and updating the list on the screen. I have a button on the screen
> that I'll call STOP that is supposed to stop the processing of the loop in
> midstream. I have a bool global variable call bStop. The OnClick for the
> stop button sets bStop to true. The loop checks the value of bStop at the
> beginning of each loop and calls break if it is true. Problem is bStop is
> never set to true until after the loop finishes. In C++ I could make a
call
> to a function that would use PeekMessage to loop through the message que
and
> Dispatch any Dialog messages so that the bStop value would be updated.
> Don't know how to do this in C#. Any ideas.
>
> Thanks in advance,
> Dave
>
>
>


Quantcast