Solved

Webclient stuck in loop

Posted on 2011-02-19
1
1,229 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
1 Comment
 
LVL 2

Accepted Solution

by:
jondow earned 500 total points
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now