Results 1 to 3 of 3

Thread: [RESOLVED] An issue about sleeping delay

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    135

    Resolved [RESOLVED] An issue about sleeping delay

    Hello,
    I am using sleeping delay between in my application - send the first serial packet and then delay a few seconds and then send the 2nd packet. The data to be sent is stored in SequenceBuffer(n1,num). The first string is teh first packet to be sent. The second string is delay value and the 3rd string is the 2nd packet to be sent. So in my code when n1 is 1 (the 2nd string), I delay a few seconds based on the string value in SequenceBuffer(1,num)

    I expect after the 1st packet is sent, there is a delay. But the delay occurred before the 1st packet sent and then sent both packets. TO make it simple, I changed to delay 10seconds. Any idea?

    Private Sub SendSequenceButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SendSequenceButton.Click
    Dim n1, n2 As Byte
    Dim DelaySecond As String = ""
    If SequenceBuffer(0, 0) = 0 Then 'if theere is at least one sequence active, SequenceBuffer(0, 0) is not 0
    MsgBox("No Active Sequence! Please Open Esisting One or Create a New One")
    Exit Sub
    End If

    'send all packets in sequence
    For n1 = 0 To 100
    If SequenceBuffer(n1, 0) = 0 Then
    Exit For
    Else 'if valid packet
    If n1 = 1 Then
    Threading.Thread.Sleep(10000)
    Else
    SendBuffer(0) = SequenceBuffer(n1, 0) 'format
    BytesSent = (SendBuffer(0) >> 4) + 1
    For n2 = 3 To BytesSent - 2
    SendBuffer(n2) = SequenceBuffer(n1, n2)
    Next
    SendBuffer(BytesSent - 1) = CalCheckSum(SendBuffer, BytesSent - 2) 'checksum

    SendPacket(BytesSent)
    End If

    End If
    Next
    End Sub

  2. #2
    PowerPoster Jenner's Avatar
    Join Date
    Jan 2008
    Location
    Mentor, OH
    Posts
    3,712

    Re: An issue about sleeping delay

    Put a:

    Code:
                        My.Application.DoEvents()
    after the SendPacket() line.

    Also, be sure to use the CODE tags to format your posted code.

    Looking at your routine, I'd recommend using a Queue to store and send your packets.
    My CodeBank Submissions: TETRIS using VB.NET2010 and XNA4.0, Strong Encryption Class, Hardware ID Information Class, Generic .NET Data Provider Class, Lambda Function Example, Lat/Long to UTM Conversion Class, Audio Class using BASS.DLL

    Remember to RATE the people who helped you and mark your forum RESOLVED when you're done!

    "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe. "
    - Albert Einstein

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2009
    Posts
    135

    Re: An issue about sleeping delay

    Quote Originally Posted by Jenner View Post
    Put a:

    Code:
                        My.Application.DoEvents()
    after the SendPacket() line.

    Also, be sure to use the CODE tags to format your posted code.

    Looking at your routine, I'd recommend using a Queue to store and send your packets.
    Thanks a lot!

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