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 read or write operations

The stream does not support concurrent I/O read or write operations

Scheduled Pinned Locked Moved C#
helpquestion
2 Posts 2 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

    R 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

      R Offline
      R Offline
      riced
      wrote on last edited by
      #2

      At a guess it is trying to use the same stream (i.e. strLocal) it is a different file but that does not mean there is more than one stream. That depends on where strLocal is declared and how the code that declares it is called. And that we don't know since it's not in your post.

      Regards David R --------------------------------------------------------------- "Every program eventually becomes rococo, and then rubble." - Alan Perlis

      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