Results 1 to 3 of 3

Thread: [2005] How to interrupt an process

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    [2005] How to interrupt an process

    how to stop an running function or subject.
    I have written an subject which when executed takes some time to finish. i have also placed an cancel button to cancel the executed of the subject.

    So i wanted to know how to cancel the execution of the subject in the middle and release the resources used.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] How to interrupt an process

    Your use of the term "subject" is incorrect. Presumably you are talking about a Sub (Sub Procedure). The name "Sub" is short for subroutine, not subject. A Sub is a method that doesn't return a value, while a Function is a method that does return a value.

    While it's not impossible to do what you're asking for in a single thread, it's really not a good idea to do so. I would suggest executing your method in a background thread. If you use a BackgroundWorker to do so then the cancellation mechanism is built in. Follow the BackgroundWorker link in my signature for an example. The example you need is in post #19.

    Just note that you can only cancel the background operation at certain points. You cannot stop it during a synchronous method call. You can only cancel the operation at places where you can specifically place code to do so.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,158

    Re: [2005] How to interrupt an process

    Ok! I will give it a try
    Thanks!

    and
    Subroutine not subject

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width