dcsimg
Results 1 to 6 of 6

Thread: Help / advice needed on loop

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    15

    Help / advice needed on loop

    I need to write a timed loop, but are unsure of how to go about it

    A int, B int

    What I need to do is

    if A <> B wait 10 seconds and check again if A = B. if not wait again 10 seconds and repeat this until A = B or it has been checked 5 times. after being checked 5 times if A <> B exit procedure

    any help or guidance please

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,098

    Re: Help / advice needed on loop

    Assuming this is a WinForms project, add a Timer to the form. Set the interval to 10000 (milliseconds, which is 10 seconds).

    To start the loop do: Timer1.Start()

    In the timer event do your checks (followed by the code you want to run when A=B). To stop the loop, do Timer1.Stop()

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    15

    Re: Help / advice needed on loop

    Sorry, I should have explained a bit more

    This is for a procedure in a CRM custom vb workflow not a windows form

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,098

    Re: Help / advice needed on loop

    In that case a System.Timers.Timer is probably a good way to go.

    Info and an example here: https://docs.microsoft.com/en-us/dot...tframework-4.8

  5. #5
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    102,754

    Re: Help / advice needed on loop

    I'm not sure whether a Timer would be the right way to go but it depends heavily on information that you haven't provided.
    This is for a procedure in a CRM custom vb workflow not a windows form
    That's still rather vague. Please provide a FULL and CLEAR explanation of the problem.

    A Timer is generally used so that something can happen regularly while the rest of the app carries on with normal service. If you have a VB module loaded into another application then a Timer may not be appropriate because the VB code may have nothing else to do in the time in between actions. A timer of some sort within that application to kick-off the VB module could be one option, but how could we know? An actual loop in the VB code might be the best option, but how could we know? We know nothing about your project other than what you tell us, so you need to tell us everything that is relevant.

  6. #6

    Thread Starter
    New Member
    Join Date
    Oct 2016
    Posts
    15

    Re: Help / advice needed on loop

    The data in CRM is being imported in via a dayasync program. Before I activate the workflow I need to ensure that all the records have been imported. I personally would have thought the sleep function would be more appropriate.

    I think I may have a solution … and once tested I will post up for comments and alternatives

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width