Solved

Webclient stuck in loop

Posted on 2011-02-19
1
1,240 Views
Last Modified: 2012-05-11
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
Comment
Question by:tonelm54
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 2

Accepted Solution

by:
jondow earned 500 total points
ID: 34933294
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question