Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1251
  • Last Modified:

Webclient stuck in loop

Good afternoon,
Ive been batteling with this code for a while now, but it just seems to be stuck in the wc.isbusy loop, it doesnt seem to exit at all.

The idea is this code is inside a SilverLight control, so when the user clicks on a button, it shows an open dialog and then uploads it to a webpage as a form.

Any ideas what Im doing wrong, why it just constently sits in the loop wc.isbusy?

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim dlgFileOpen As New OpenFileDialog

        dlgFileOpen.Multiselect = False
        dlgFileOpen.ShowDialog()

        If dlgFileOpen.Files.Count > 0 Then
            For x = 0 To dlgFileOpen.Files.Count - 1
                Dim input As FileStream = dlgFileOpen.Files(x).OpenRead()

                Dim count As Integer = 250
                Dim buffer(count - 1) As Byte

                count = input.Read(buffer, 0, count)
                Do Until count = 0
                    uploadBit("123455", buffer)
                    count = input.Read(buffer, 0, count)
                Loop
            Next
        End If
    End Sub

    Function uploadBit(ByVal strID As String, ByVal bytBit() As Byte) As Boolean
        Dim encoding As New System.Text.UTF8Encoding
        Dim wc As New System.Net.WebClient()

        Dim d As String = "strID=" & strID & "&valBlob=" & UrlEncode(bytBit.ToString)

        wc.UploadStringAsync(New Uri("http://localhost:53679/upload.aspx"), "POST", d)

        Do Until wc.IsBusy = False
            System.Threading.Thread.Sleep(100)
        Loop

        Return True
    End Function

Open in new window


Thanks in advance, for any assistance!
0
tonelm54
Asked:
tonelm54
1 Solution
 
jondowCommented:
I wonder if its a threading related problem, try

            while wc.IsBusy
                System.Threading.Thread.Sleep(0) 'Specify zero to indicate that this thread should be suspended to allow other waiting threads to execute
            end while
            wc.Dispose()
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now