Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. The stream does not support concurrent I/O ReadWrite operations

The stream does not support concurrent I/O ReadWrite operations

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mbyamukama
    wrote on last edited by
    #1

    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

    C L 2 Replies Last reply
    0
    • M mbyamukama

      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

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Sounds like you're trying to write to the same file on two threads ? That plainly won't work.

      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

      1 Reply Last reply
      0
      • M mbyamukama

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        What is the actual value of "SaveAsTextBox.Text" in each of the threads?

        M 1 Reply Last reply
        0
        • L Lost User

          What is the actual value of "SaveAsTextBox.Text" in each of the threads?

          M Offline
          M Offline
          mbyamukama
          wrote on last edited by
          #4

          for each of the threads, it is different. say AAA.avi for one and BBB.avi for another. The two are meant to be written to the same forlder nonetheless.

          BHM

          L 1 Reply Last reply
          0
          • M mbyamukama

            for each of the threads, it is different. say AAA.avi for one and BBB.avi for another. The two are meant to be written to the same forlder nonetheless.

            BHM

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            Maximus Byamukama wrote:

            say AAA.avi for one and BBB.avi for another. The two are meant to be written to the same forlder nonetheless.

            Yes, but what are the actual values? Have you checked the filenames in both threads at execution time?

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups