Results 1 to 6 of 6

Thread: Separate Task or Time Calculation - Code Suggestion

Threaded View

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2013
    Posts
    177

    Separate Task or Time Calculation - Code Suggestion

    Hi,

    This might be more personal preference but i’d Like to know peoples ideas on why they’d do this problem one way or the other.

    All of this is happening on a separate background thread, so you don’t have to worry about blocking the UI or anything.

    In this thread I have 2 tasks to do:

    1. has to be done every 0.5Seconds

    2. Can vary between needing to be done once every 1 second or every 30 seconds.

    The two options I see
    VB Code:
    1. Dim StartTime = Datetime.Now
    2. Dim Interval as Double= (input)
    3. While [Condotion]
    4.    ‘Do task one
    5.     If (task1outcome =False)
    6.        Exit While
    7.     End if
    8.    If StartTime.Subtract(DateTime.Now) > Interval Then
    9.      ‘Do task two
    10.       StartTime = Datetime.now
    11.  
    12.    End if
    13.    Thread.Sleep(500)’ms
    14.  
    15. End While
    16.  
    17. ‘—————— Option 2 ————
    18.  
    19. While [Condition]
    20.   ‘Do task 2
    21.   Thread.Sleep(Interval)
    22. End While
    23.  
    24. ‘The above code would be Run in a task
    25.  
    26. While [Condition]
    27.  ‘Do task 1
    28.   If (task1outcome = False) Then
    29.       Stop Task
    30.       Exit While
    31.   End If  
    32.   Thread.Sleep (500) ‘ms
    33. End While

    Sorry for the bad Pseudo code, but this was semi bothering me and I’m on my phone.
    Last edited by Crzyrio; Oct 15th, 2018 at 10:23 PM.

Tags for this Thread

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