How to Stop a Process

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All
I am creating a C# app, in which there are some methods that are considerably longer than the others and take a few minutes to complete, I want to give the users an option to stop that method (which is in process).
I want to include a command button using which the user of the app, can stop that process. Another thing that i want to add is that, while stopping the mthod execution, i do not want the Windows Form to close, only the in process method to stop
Any help would be greatly appreciated

With Regard
Sunn
 
Sunny said:
Hi All,
I am creating a C# app, in which there are some methods that are
considerably longer than the others and take a few minutes to
complete, I want to give the users an option to stop that method
(which is in process).
I want to include a command button using which the user of the app,
can stop that process. Another thing that i want to add is that,
while stopping the mthod execution, i do not want the Windows Form to
close, only the in process method to stop. Any help would be greatly
appreciated.

Take a look at System.Threading.Thread, System.Threading.ThreadStart
delegate, and Thread.Abort.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
 
Sunny said:
I am creating a C# app, in which there are some methods that are
considerably longer than the others and take a few minutes to
complete, I want to give the users an option to stop that method
(which is in process).

I want to include a command button using which the user of the app,
can stop that process. Another thing that i want to add is that, while
stopping the mthod execution, i do not want the Windows Form to close,
only the in process method to stop.

Any help would be greatly appreciated.

I *suspect* you mean the method is in another thread, not another
process. If so, the best thing is to make the thread check a flag
periodically, and set that flag from the button's event. Note that you
should use "lock" round the section of code used to set (and check) the
flag.
 
Take a look at the Process.Kill() Method (a member of the Process Class).It Stops the process.
 
Back
Top