none
How do I make an infinite repeating function?

    Question

  • So, I'm making a performance optimization program and I've created some code so that when the startup program opens it will block suspicious files. However, I've tested it and it only kills the process if its open when it opens. How do I make a repeating function that infinitely repeats until the program closes? 
    Tuesday, April 25, 2017 12:46 AM

Answers

  • So, you answer works, however, is there a way to make it less memory consuming?

    If you mean CPU consuming, then use a timer. (Or let the thread sleep a bit in the loop...) For memory issues, make sure that you dispose every object that implements IDisposable, eg by using "using blocks".

    Regards,

      Thorsten



    Thursday, April 27, 2017 10:49 AM

All replies

  • Hi VBProgrammer456,

    According to your description, you can use the code below to achieve an infinite repeating function.

    Private Sub fun()
            While True
                ' some code
            End While
        End Sub

    Best Regards,

    Cherry Bu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, April 27, 2017 7:45 AM
    Moderator
  • So, I'm making a performance optimization program and I've created some code so that when the startup program opens it will block suspicious files. However, I've tested it and it only kills the process if its open when it opens. How do I make a repeating function that infinitely repeats until the program closes? 

    Hi,

    you could use a timer to repeat your action(s) at a given interval.

    Regards,

      Thorsten

    Thursday, April 27, 2017 8:23 AM
  • Thanks everyone for the replies! I'll try these out.
    Thursday, April 27, 2017 10:11 AM
  • So, you answer works, however, is there a way to make it less memory consuming?
    Thursday, April 27, 2017 10:22 AM
  • So, you answer works, however, is there a way to make it less memory consuming?

    If you mean CPU consuming, then use a timer. (Or let the thread sleep a bit in the loop...) For memory issues, make sure that you dispose every object that implements IDisposable, eg by using "using blocks".

    Regards,

      Thorsten



    Thursday, April 27, 2017 10:49 AM
  • Ok, thanks!
    Friday, April 28, 2017 10:24 AM