Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am going to upload an RAR file on Amazon Server. the folder is around 30MB.

I have tried to to upload this rar file using BackGroudWorker and Thread but not getting the solution. If i remove thread and backgroudworker than also getting the following error.

"The CLR has been unable to transition from COM context
0x2183e0 to COM context 0x218550 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."

My application is in VB.NET windows based. I have two Function.. AmazonS3 Client, Filename , Path, and Str3_Key for amazon
here is the code:
VB
Public Sub CreateNewFile(client As AmazonS3, filename As String, filepath As String, strs3_key As String)
Try
Cursor.Current = Cursors.WaitCursor
Dim S3_KEY As [String] = strs3_key
Dim request As New PutObjectRequest()
request.WithBucketName(amazon_bucket_name)
request.WithKey(S3_KEY)
request.WithContentBody("")
client.PutObject(request)
UploadFile(client, S3_KEY, filepath)
Cursor.Current = Cursors.Default
Catch ex As Exception
Cursor.Current = Cursors.Default
MessageBox.Show(ReadException(ex))
End Try

End Sub
Public Shared Sub UploadFile(client As AmazonS3, S3_key As String, FilePath As String)
Try
Dim request As New PutObjectRequest()
request.WithBucketName(amazon_bucket_name)
request.WithKey(S3_key)
request.WithFilePath(FilePath)
client.PutObject(request)
Catch ex As Exception

End Try
End Sub
Posted
Updated 24-Sep-15 3:59am
v3
Comments
Leo Chapiro 24-Sep-15 10:04am    
You need to use BackgroundWorker, take a look at this example please: http://www.visual-basic-tutorials.com/Tutorials/Controls/BackGroundWorker.htm . Let run your Sub UploadFile in the new thread .
Nishant2852 25-Sep-15 5:26am    
I have also tried this..but able to solve error.

here is my code..
Private Sub bgWorker_DoWork(sender As Object, e As DoWorkEventArgs) Handles bgWorker.DoWork
Dim fi As New System.IO.FileInfo(OpenFileDialog1.FileName)
If fi.Length > 5000 Then
thrdFile = New Thread(AddressOf UploadFile)
thrdFile.SetApartmentState(ApartmentState.STA)
thrdFile.IsBackground = True
thrdFile.Start()
Else
UploadFile()
End If
Dim cnt_temp As Integer = 1
pBar.Maximum = 100
While thrdFile.IsAlive = True
System.Threading.Thread.Sleep(500)
cnt_temp = cnt_temp + 1
If cnt_temp > pBar.Maximum Then
cnt_temp = 1
End If
bgWorker.ReportProgress(cnt_temp)
End While
End Sub
Nishant2852 25-Sep-15 5:32am    
When i put code in thread than it doesnt throw any error. when i put code outside of thread it throws below error.

Managed Debugging Assistant 'ContextSwitchDeadlock' has detected a problem in 'C:\Users\Windows\Desktop\Test\WorkHives\WorkHives\bin\Debug\WorkHives.vshost.exe'.

Additional information: The CLR has been unable to transition from COM context 0x1068ff0 to COM context 0x10690a8 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.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900