943,657 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 3709
  • VB.NET RSS
Jun 11th, 2009
0

Thread.suspend and thread.resume is obsolete

Expand Post »
Hello

I am coding an FTP program, the downloading/uploading happens in a seperate thread. The problem is now how to pause/resume the download (even on servers that don't support file resume), an easy/working way is to pause/resume the working thread with thread.suspend but it tells me that this function is obsolete.

Is there a simmilar method to achieve this? I've tried looking up Mutexes, Monitor, Event, Semaphore stuff but that would only allow me to pause the file transfer after the file is done.

So the code that 'lives' in the thread that I want to suspend looks something like

vb Syntax (Toggle Plain Text)
  1. Private Sub StartUpload(ByVal allFiles As Hashtable)
  2. For Each singleFile As String In allFiles.Keys
  3. Try
  4. ftpClient.UploadFile(singleFile, allFiles.Item(singleFile), False)
  5. Catch ex As Exception
  6. ftpClient.DeleteFile(allFiles.Item(singleFile))
  7. Exit For
  8. End Try
  9. Next
  10. allFiles = Nothing
  11. End Sub
Function get called as following:
vb Syntax (Toggle Plain Text)
  1. UploadThread = New Threading.Thread(AddressOf StartUpload)
  2. UploadThread.Start(allFiles)

So UploadThread.suspend() / resume works perfectly, but I can't really release this if these functions get removed in future releases of .net

Any help is appreciated

GeekByChoiCe
Similar Threads
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009
Jun 11th, 2009
0

Re: Thread.suspend and thread.resume is obsolete

I don't believe that support for these methods will be removed in any future release, for backwards compatability. The reason for it being marked as obsolete is because when suspending a thread, you cannot determine where in the method the thread suspends at. Instead, you should generally use a boolean variable, and have the method check at certain points the value of the variable, and suspend the thread using a while loop or something.
Reputation Points: 69
Solved Threads: 48
Posting Whiz in Training
nmaillet is offline Offline
203 posts
since Aug 2008
Jul 5th, 2009
0

Re: Thread.suspend and thread.resume is obsolete

Almost forgot to mark it as solved d'oh

Actually after days of trying i figured out that Thread.Suspend is exactlly what i shouldn't do o.O
When i suspend the FTP Upload it works perfect for exact the time until the FTP server timeouts and disconnect. If i then want to resume my Upload it fails ofc.
Anyway it seems i still have two possibilities:
1. pausing the transfer after the current file is uploaded (if uploading multiple files)
2. saving the count of current transfered bytes and sending the resume command to the ftp server by giving the count as argument. But not all FTP server are set up to support file resume. so guess option 1 wit will be.

Problem solved.
Featured Poster
Reputation Points: 208
Solved Threads: 168
Practically a Master Poster
GeekByChoiCe is offline Offline
692 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: how to upload a photo to a form in vb.net
Next Thread in VB.NET Forum Timeline: dropdown





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC