ERLEDIGT
JA
JA
ANTWORTEN
5
5
ZUGRIFFE
832
832
EMPFEHLEN
-
11.02.10 11:17 #1
- Registriert seit
- Apr 2008
- Beiträge
- 101
Hallo,
Ich baue gerade in C# einen Downloadmanager. Nun habe ich das Problem das wenn ich zwei Threads die downloaden Parallel starten will die Exception:
{"Der Stream unterstützt keine gleichzeitigen E/A-Lese- oder Schreibvorgänge."} auslöst
Code der Downloadmethode:
Ich starte die Methode, dann in verschiedenen Threads, und dann wieder wird die Exception geschmissen. Weiß zufällig jemand wie ich das umgehen kann?Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
public static void DownloadF(object startPoint, string Url, string Path, DataGridViewProgressCell prgDownload, DataGridView view) { try { // Put the object argument into an int variable int startPointInt = Convert.ToInt32(startPoint); // Create a request to the file we are downloading webRequest = (HttpWebRequest)WebRequest.Create(Url); // Set the starting point of the request webRequest.AddRange(startPointInt); // Set default authentication for retrieving the file webRequest.Credentials = CredentialCache.DefaultCredentials; // Retrieve the response from the server webResponse = (HttpWebResponse)webRequest.GetResponse(); // Ask the server for the file size and store it Int64 fileSize = webResponse.ContentLength; // Open the URL for download strResponse = webResponse.GetResponseStream(); // Create a new file stream where we will be saving the data (local drive) if (startPointInt == 0) { strLocal = new FileStream(Path, FileMode.Create, FileAccess.Write, FileShare.None); } else { strLocal = new FileStream(Path, FileMode.Append, FileAccess.Write, FileShare.None); } // It will store the current number of bytes we retrieved from the server int bytesSize = 0; // A buffer for storing and writing the data retrieved from the server byte[] downBuffer = new byte[2048]; // Loop through the buffer until the buffer is empty while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0) //HIER LÖST DER FEHLER AUS { // Write the data from the buffer to the local hard drive strLocal.Write(downBuffer, 0, bytesSize); // Invoke the method that updates the form's label and progress bar view.Invoke(new UpdateProgessCallback(UpdateProgress), new object[] { strLocal.Length, fileSize + startPointInt,prgDownload }); if (goPause == true) { break; } } } finally { // When the above code has ended, close the streams strResponse.Close(); strLocal.Close(); view.Invoke(new UpdateStatusCallback(UpdateStatus), new object[] {Status.DOWNLOADED,prgDownload,view }); }
-
Versuch mal FileShare.None durch FileShare.Write zu ersetzen.
hihi = -h²
-
11.02.10 16:03 #3
- Registriert seit
- Apr 2008
- Beiträge
- 101
Leider gleiches Verhalten
-
An welcher Stelle genau wird welche Exception geschmissen?
hihi = -h²
-
11.02.10 17:26 #5
- Registriert seit
- Apr 2008
- Beiträge
- 101
Habs gescreent
-
11.02.10 18:51 #6
- Registriert seit
- Apr 2008
- Beiträge
- 101
Problem gelöst ich depp hab den Filestream usw ja ausserhalb der STATISCHEN METHODE und STATISCH deklariert....
Ähnliche Themen
-
Dateidownload mit PHP
Von queicherius im Forum PHPAntworten: 6Letzter Beitrag: 31.08.09, 20:29 -
Dateidownload
Von Rene Winklewski im Forum JavaAntworten: 3Letzter Beitrag: 31.01.08, 11:22 -
Dateidownload txt
Von saila im Forum PHPAntworten: 4Letzter Beitrag: 15.02.07, 18:31 -
Dateidownload
Von Soapp im Forum PHPAntworten: 7Letzter Beitrag: 21.03.06, 13:10 -
Dateidownload
Von BigChicken im Forum PHPAntworten: 5Letzter Beitrag: 27.04.05, 14:03





Zitieren
Login





