Error While Large File Uploading
-
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(); for Small file size it works fine. Thanks sjs