Link to home
Start Free TrialLog in
Avatar of tonelm54
tonelm54

asked on

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!
ASKER CERTIFIED SOLUTION
Avatar of jondow
jondow
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial