vb.net help please

Discussion in 'Programming' started by navifier, Jul 14, 2011.

  1. #1
    So i'm making an animation in .net using timers. and the execution of those timers is linked with a for loop. To make it more clear, imagine that for each loop iterration a timer is running for 5 sec. Now my problem is that the loop is not waiting for timer (animation) to finish, and it jumps to the next itrration ( i+1 ). Now how can i make a loop wait for timers to be in enabled = false ( this means animation is finished ) and then proces the next iterration.

    Here is the example of the loop.
    
        For i As Integer = 0 To 7
                If panele(i).Tag > panele(i + 1).Tag Then
                    swap(panele(i + 1), panele(i))
    
                End If
            Next
    
    Code (markup):
    and i need the for loop to wait for the function swap to be finished before it continues on the next. and swap() lasts about 2 sec.
     
    navifier, Jul 14, 2011 IP
  2. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #2
    Just to clarify, are you using loops as timers or are you using functions to record time which are then used in loops? Unless you're using multi-threading, your swap function does finish and return before control is returned back to the loop.
     
    BRUm, Jul 14, 2011 IP
  3. navifier

    navifier Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    Hey,

    Thanks for trying to help, but i have found a solution already.
     
    navifier, Jul 14, 2011 IP
  4. BRUm

    BRUm Well-Known Member

    Messages:
    3,086
    Likes Received:
    61
    Best Answers:
    1
    Trophy Points:
    100
    #4
    OK no problem. Mind sharing what your solution was?
     
    BRUm, Jul 14, 2011 IP
  5. navifier

    navifier Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #5
    Well since i only needed the swap function results with delay of 5 sec, i have let the loop store each result in listbox, then i just added an extra timer and read one by one result from listbox every 5 sec with a timer.
     
    navifier, Jul 14, 2011 IP
  6. rnvr22

    rnvr22 Active Member

    Messages:
    290
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #6
    use delay(sec) function just before the NEXT with the number of seconds as in your animation... hope this helps
     
    rnvr22, Jul 16, 2011 IP
  7. navifier

    navifier Member

    Messages:
    27
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #7
    I don't know about the delay function but if you mean system.threading.sleep(sec), then that would be a bad solution cuz i have a running animation in the background and that would stop it too ( freeze the program ), unless if i use multithreading but then it's just complicated. I think the solution that i made with the timers is ok.

    Thanks for the help
     
    navifier, Jul 16, 2011 IP