CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2001
    Location
    Utah USA
    Posts
    13

    How to abort a tight loop

    I have a class module that processes image data. It may process hundreds or thousands of images per pass. Once I call the go method I want to be able to abort the process. I thought I could add a property called abort and check for it each loop. If true I would terminate the loop. I have a command button on the form that calls the class called abort. It just sets the classes abort property to true. I have also included a DoEvents in the loop so the button click gets processed. This works fine but the abort property never gets set. If I check a control on the form from the class for abort (say an abort check box) rather than looking at the abort propery it works.

    Any ideas how to abort a class method reliably without external controls?

    Thanks

    Craig

  2. #2
    Join Date
    Jun 2001
    Location
    MO, USA
    Posts
    2,868

    Re: How to abort a tight loop

    I believe this is what you said you tried, but just to be sure

    In a form:

    option Explicit
    Dim oLoop as LoopObject

    private Sub Command1_Click()
    oLoop.Cancel = true
    End Sub

    private Sub Command2_Click()
    set oLoop = new LoopObject
    oLoop.Looper
    End Sub




    In a class module...


    option Explicit
    Dim bCancel as Boolean

    public property let Cancel(b as Boolean)
    bCancel = b
    End property

    public Sub Looper()
    Do While Not bCancel
    DoEvents
    Loop
    End Sub




    This should work.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured