Error while uploading large file
-
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
-
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
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
-
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
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
-
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
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
-
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
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
-
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
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