Forum: VB.NET |
Thema:
UploadFile - Thread bleibt hängen |
Von:
G. Guest (
19.05.2006 15:08) |
hallo zusammen!
habe folgendes für einen Asynchronen Upload gefunden:
http://msdn2.microsoft.com/de-de/library/system.net.uploadfilecompletedeventhandler(VS.80).aspx
Hab den Quellcode so kopiert und abgeändert, dass auf FTP geuploaded wird. Mein Code sieht jetzt folgendermassen aus:
[code]
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
UploadFileInBackground("ftp://ftp.meinserver.com/bild1.jpg", "bild1.jpg")
End Sub
' Sample call: UploadFileInBackground("http:' www.contoso.com/fileUpload.aspx", "data.txt")
Public Shared Sub UploadFileInBackground(ByVal address As String, ByVal fileName As String)
Dim waiter As System.Threading.AutoResetEvent = New System.Threading.AutoResetEvent(False)
Dim client As WebClient = New WebClient()
Dim method As String = "STOR"
Dim uri As Uri = New Uri(address)
' Specify that that UploadFileCallback method gets called
' when the file upload completes.
AddHandler client.UploadFileCompleted, AddressOf UploadFileCallback
client.Credentials = New NetworkCredential("user", "password")
client.UploadFileAsync(uri, method, fileName, waiter)
' Block the main application thread. Real applications
' can perform other tasks while waiting for the upload to complete.
waiter.WaitOne()
Console.WriteLine("File upload is complete.")
End Sub
Public Shared Sub UploadFileCallback(ByVal sender As Object, ByVal e As System.Net.UploadFileCompletedEventArgs)
Dim waiter As System.Threading.AutoResetEvent = CType(e.UserState, System.Threading.AutoResetEvent)
Try
Dim reply As String = System.Text.Encoding.UTF8.GetString(e.Result)
Console.WriteLine(reply)
Finally
' If this thread throws an exception, make sure that
' you let the main application thread resume.
waiter.Set()
End Try
End Sub
[/code]
Wenn ich den Befehl nun ausführe bleibt mir die Applikation immer bei "waiter.WaitOne()" hängen. Was mache ich falsch?
Grüsse Crawn
Betreff |
Von |
Datum |
|
|
Ralf
Ehlert
|
13.08.2006 17:42 |
|
|
Antworten
Vorsicht bei der Eingabe: Die Zeichen ' oder -- sind nicht erlaubt!