locked
Stop Loop In Delegate RRS feed

  • Question

  • Ok, so I know how to stop a regular loop inside a regular sub or function, but I don't know how to do it with a shared delegate. I always get an error saying I can't access a resource from a shared object or something like that haha. Here's my code:

    [code]

    Public

    ReadOnlyThreadMainDelegate1 AsNewAction(OfInteger, Color,Boolean)(AddressOfThreadMain1)

    PrivateSharedSubThreadMain1(ByValNumber As Integer, ByValColor AsColor,ByValStopButton AsBoolean)

    Do


                       

    IfStopButton = TrueThen


                           

    Exit Do


                       

    EndIf

    Loop

    Saturday, December 22, 2012 6:18 PM

Answers

  • You should not be passing the StopButton in as a parameter to the function.  I would make stopbutton a property or form or class level variable you can set to false to stop the loop
    • Marked as answer by Youen Zen Thursday, January 3, 2013 8:33 AM
    Saturday, December 22, 2012 6:21 PM
  • A thread is a process which has a start and end, it is not a kind of process which you can stop and start again,

    Be aware, you are not the first one who tries this, but it fails. The Thread has no events the messages can sometimes be confusing.


    Success
    Cor

    Saturday, December 22, 2012 6:40 PM
  • "Ok, so I know how to stop a regular loop inside a regular sub or function, but I don't know how to do it with a shared delegate."

    A delegate is essentially a reference to a regular sub or function.  Post your code "to stop a regular loop inside a regular sub or function".  Use the code formatting tool (second icon from the right, the one with <>) to post code.

    Saturday, December 22, 2012 8:32 PM

All replies

  • Ok, it is extremely hard to post code on these forums, so I only posted what was needed. Hope you can sitll help. :D
    Saturday, December 22, 2012 6:19 PM
  • You should not be passing the StopButton in as a parameter to the function.  I would make stopbutton a property or form or class level variable you can set to false to stop the loop
    • Marked as answer by Youen Zen Thursday, January 3, 2013 8:33 AM
    Saturday, December 22, 2012 6:21 PM
  • A thread is a process which has a start and end, it is not a kind of process which you can stop and start again,

    Be aware, you are not the first one who tries this, but it fails. The Thread has no events the messages can sometimes be confusing.


    Success
    Cor

    Saturday, December 22, 2012 6:40 PM
  • You should not be passing the StopButton in as a parameter to the function.  I would make stopbutton a property or form or class level variable you can set to false to stop the loop

    oK, how can I go about this?
    Saturday, December 22, 2012 8:17 PM
  • "Ok, so I know how to stop a regular loop inside a regular sub or function, but I don't know how to do it with a shared delegate."

    A delegate is essentially a reference to a regular sub or function.  Post your code "to stop a regular loop inside a regular sub or function".  Use the code formatting tool (second icon from the right, the one with <>) to post code.

    Saturday, December 22, 2012 8:32 PM