Click here to Skip to main content
15,902,933 members

Comments by Nishant2852 (Top 3 by date)

Nishant2852 25-Sep-15 5:32am View    
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.
Nishant2852 25-Sep-15 5:26am View    
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 24-Sep-15 9:46am View    
Deleted
I have two Function.. AmazonS3 Client, Filename , Path, and Str3_Key for amazon
here is the code

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