المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : The stream does not support concurrent I/O read or write operations



C# Programming
08-25-2009, 06:22 PM
I am writing a multithreaded application. A download manager to be precise. When downloading one file, everything is quite fine. The thread starts, downloads the file and terminates as expected. When i start another download thread, however, when the first is still running, i get the error above 9in the subject). The problem is on this line of code which is meant to create a new filestream and write the retrieved data to the stream.
strLocal = new FileStream(Application.StartupPath+"\\"+SaveAsTextBox.Text,FileMode.Create, FileAccess.Write,FileShare.ReadWrite);

The download method is called Download(), is void and does not take any arguments.
A thread is started using
DownloadThread[j] = new Thread(new ThreadStart(Download));
DownloadThread[j].Start();


where j has a value incremented per click, so as to start a new thread each time.
What i do not understand is that the exception seems to suggest that 2 write operations are requesting to be handled by the same stream, yet it is actually a different stream because the user changes the SaveAsTextBox.Text on every new download.
Any answers?

BHM