tutorials.de Buch-Aktion 05/2012
ERLEDIGT
JA
ANTWORTEN
5
ZUGRIFFE
832
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    Ichbinalex Ichbinalex ist offline Mitglied Gold
    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:
    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 });
                }
    Ich starte die Methode, dann in verschiedenen Threads, und dann wieder wird die Exception geschmissen. Weiß zufällig jemand wie ich das umgehen kann?
     

  2. #2
    Avatar von Shakie
    Shakie Shakie ist offline Mitglied Diamant
    Registriert seit
    May 2004
    Ort
    Europa
    Beiträge
    2.048
    Versuch mal FileShare.None durch FileShare.Write zu ersetzen.
     
    hihi = -h²

  3. #3
    Ichbinalex Ichbinalex ist offline Mitglied Gold
    Registriert seit
    Apr 2008
    Beiträge
    101
    Leider gleiches Verhalten
     

  4. #4
    Avatar von Shakie
    Shakie Shakie ist offline Mitglied Diamant
    Registriert seit
    May 2004
    Ort
    Europa
    Beiträge
    2.048
    An welcher Stelle genau wird welche Exception geschmissen?
     
    hihi = -h²

  5. #5
    Ichbinalex Ichbinalex ist offline Mitglied Gold
    Registriert seit
    Apr 2008
    Beiträge
    101
    Habs gescreent
    Miniaturansicht angehängter Grafiken Miniaturansicht angehängter Grafiken Paraleller Dateidownload-fehler.jpg  
     

  6. #6
    Ichbinalex Ichbinalex ist offline Mitglied Gold
    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

  1. Dateidownload mit PHP
    Von queicherius im Forum PHP
    Antworten: 6
    Letzter Beitrag: 31.08.09, 20:29
  2. Dateidownload
    Von Rene Winklewski im Forum Java
    Antworten: 3
    Letzter Beitrag: 31.01.08, 11:22
  3. Dateidownload txt
    Von saila im Forum PHP
    Antworten: 4
    Letzter Beitrag: 15.02.07, 18:31
  4. Dateidownload
    Von Soapp im Forum PHP
    Antworten: 7
    Letzter Beitrag: 21.03.06, 13:10
  5. Dateidownload
    Von BigChicken im Forum PHP
    Antworten: 5
    Letzter Beitrag: 27.04.05, 14:03