Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Webclient stuck in loop

Posted on 2011-02-19
1
Medium Priority
?
1,248 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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 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