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
  1. Home
  2. General Programming
  3. C#
  4. Error while uploading large file

Error while uploading large file

Scheduled Pinned Locked Moved C#
performancehelpquestionmobiledotnet
6 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.
  • S Offline
    S Offline
    sjs4u
    wrote on last edited by
    #1

    Hi, I am using webclient while uploading large file(135MB) using windows application. My Code works but when it reaches to stream.close() it showing following error Error:- The CLR has been unable to transition from COM context 0x1ff030 to COM context 0x1ff1a0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations. So because of that my file is not uploaded. what is the problem? My Code is:- WebClient client = new WebClient(); Stream stream = client.OpenWrite(remoteFilename, "PUT"); // The buffer size is set to 2kb const int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; // Opens a file stream (System.IO.FileStream) to read the file // to be uploaded FileStream fs = fileInf.OpenRead(); int doneSoFar = 0; // Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength); //added for accurate progress doneSoFar += contentLen; setItemStatus("Uploading"); while (contentLen != 0) { setItemProgress(doneSoFar, fileInf.Length); // Write Content from the file stream to the FTP Upload Stream stream.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); doneSoFar += contentLen; } // Close the file stream and the Request Stream stream.Close(); fs.Close(); Thanks sjs

    N 1 Reply Last reply
    0
    • S sjs4u

      Hi, I am using webclient while uploading large file(135MB) using windows application. My Code works but when it reaches to stream.close() it showing following error Error:- The CLR has been unable to transition from COM context 0x1ff030 to COM context 0x1ff1a0 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations. So because of that my file is not uploaded. what is the problem? My Code is:- WebClient client = new WebClient(); Stream stream = client.OpenWrite(remoteFilename, "PUT"); // The buffer size is set to 2kb const int buffLength = 2048; byte[] buff = new byte[buffLength]; int contentLen; // Opens a file stream (System.IO.FileStream) to read the file // to be uploaded FileStream fs = fileInf.OpenRead(); int doneSoFar = 0; // Read from the file stream 2kb at a time contentLen = fs.Read(buff, 0, buffLength); //added for accurate progress doneSoFar += contentLen; setItemStatus("Uploading"); while (contentLen != 0) { setItemProgress(doneSoFar, fileInf.Length); // Write Content from the file stream to the FTP Upload Stream stream.Write(buff, 0, contentLen); contentLen = fs.Read(buff, 0, buffLength); doneSoFar += contentLen; } // Close the file stream and the Request Stream stream.Close(); fs.Close(); Thanks sjs

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      First, please format any code you post using the pre tags. Have you tried just using WebClient.UploadFile or WebClient.UploadFileAsync ?


      I know the language. I've read a book. - _Madmatt

      S 1 Reply Last reply
      0
      • N Not Active

        First, please format any code you post using the pre tags. Have you tried just using WebClient.UploadFile or WebClient.UploadFileAsync ?


        I know the language. I've read a book. - _Madmatt

        S Offline
        S Offline
        sjs4u
        wrote on last edited by
        #3

        Ok. Let me specify what I am actually doing. I am using windows application for uploading file on server. My client applications were using by our various CLIENT's. In that I am using one folder where there will be more files in that and once CLIENT's finish there work they save it to that folder. then by using threading concept I am fetching all the files and uploaded on the server. Also in that I need to check the size of files that is being uploaded on the server. In that I dont want to set some credential like username and password. By using your solution webclient.uploadfile() is this will work. How can i use Webclient.UploadfileAsync? Thanks sjs

        modified on Saturday, April 10, 2010 7:38 AM

        N 1 Reply Last reply
        0
        • S sjs4u

          Ok. Let me specify what I am actually doing. I am using windows application for uploading file on server. My client applications were using by our various CLIENT's. In that I am using one folder where there will be more files in that and once CLIENT's finish there work they save it to that folder. then by using threading concept I am fetching all the files and uploaded on the server. Also in that I need to check the size of files that is being uploaded on the server. In that I dont want to set some credential like username and password. By using your solution webclient.uploadfile() is this will work. How can i use Webclient.UploadfileAsync? Thanks sjs

          modified on Saturday, April 10, 2010 7:38 AM

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          sjs4u wrote:

          Let me specify what I am actually doing.

          That would have nice to do in the first post. :rolleyes:

          sjs4u wrote:

          webclient.uploadfile() is this will work.

          Why?

          sjs4u wrote:

          How can i use Webclient.UploadfileAsync?

          RTFM


          I know the language. I've read a book. - _Madmatt

          S 1 Reply Last reply
          0
          • N Not Active

            sjs4u wrote:

            Let me specify what I am actually doing.

            That would have nice to do in the first post. :rolleyes:

            sjs4u wrote:

            webclient.uploadfile() is this will work.

            Why?

            sjs4u wrote:

            How can i use Webclient.UploadfileAsync?

            RTFM


            I know the language. I've read a book. - _Madmatt

            S Offline
            S Offline
            sjs4u
            wrote on last edited by
            #5

            webclient.uploadfile() :- for This should I have to write credential? Right Now my path is http://loacalhost/server/file.wav. as i m uploading .wav file. Why I am saying that I want to use same code only for uploading the file. I will check..Thanks

            N 1 Reply Last reply
            0
            • S sjs4u

              webclient.uploadfile() :- for This should I have to write credential? Right Now my path is http://loacalhost/server/file.wav. as i m uploading .wav file. Why I am saying that I want to use same code only for uploading the file. I will check..Thanks

              N Offline
              N Offline
              Not Active
              wrote on last edited by
              #6

              sjs4u wrote:

              want to use same code only for uploading the file.

              What???

              sjs4u wrote:

              This should I have to write credential?

              Why? Does the website you are posting to require login?

              sjs4u wrote:

              I will check

              This is the only part of your response that makes sense


              I know the language. I've read a book. - _Madmatt

              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