473,698 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Stop a Process

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

Nov 15 '05 #1
3 15448
Sunny wrote:
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.Threadin g.Thread, System.Threadin g.ThreadStart
delegate, and Thread.Abort.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
Nov 15 '05 #2
Sunny <gh**********@y ahoo.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #3
Take a look at the Process.Kill() Method (a member of the Process Class).It Stops the process.
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2854
by: Prasad | last post by:
Hi, I am writing a service which takes a long time to stop after the OnStop call is given by the Services Snap-in. The problem is I cannot cut down on the time that it takes to Stop. The Service snap-in gives me the error saying that the service did not respond to the Stop call in a timely fashion. So is there any method by which I can get around this problem. Thanks Prasad
12
2265
by: Vadym Stetsyak | last post by:
Hi there! Is there any way how can I stop garbage collection for a period of time. Lets say, I have a form. Before form load I pause the GC and when the form is shown resume GC
0
1286
by: strangedub | last post by:
I am working on a C# Windows program that needs to kill a known process. I have written code that works in development mode but hits an "Access Denied" exception when running the compiled program: Here's my original code: // Now stop the server process Process myProcesses; myProcesses = Process.GetProcessesByName("MyServer"); foreach(Process myProcess in myProcesses) {
2
1762
by: ENathan | last post by:
I have a public sub in a class that does something like: If ValuesChanged() Then UpdateDatabase End If ValuesChanged and UpdateDatabase are Private functions within the class. My problem is, when I finish debugging ValuesChanged and click the stop debugging button, it appears the code continues behind these scenes and runs
4
1956
by: Chip | last post by:
Can somebody explain to me why my process continues to run after I halt execution? This plays havoc with debugging. I expect to be starting a new instance at the beginning of a loop and the first break point hit is thousands of itterations into the process (from a previous instance). I get a very random step behavior. Know I am watching a database continue to be updated 10 minutes after I stopped the front-end process. I have to stop IIS...
5
8987
by: Torben Laursen | last post by:
Hi My interface calls a C++ dll that runs a slow calculations. So I call the dll inside a BackgroundWorker thread, and that all works fine. But how can I stop the thread if the user wants to? I can not tell the dll to stop so CancelAsync() will not work? I need a way to simply kill the "thread" since nothing in it will be used if the user wants to cancel
2
1582
by: srcleveland | last post by:
I am trying to have a windows service stop itself. I am currently using the following code but I would like to find a way to stop the service without having to shell out to a command prompt Process p = new Process(); p.StartInfo.FileName = "cmd.exe"; p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; p.StartInfo.Arguments = " /C sc stop \"" + this.serviceDisplayName + "\""; p.Start();
10
5175
by: ThunderMusic | last post by:
Hi, I'm currently working with sockets. I accept connections using m_mySocket.Listen(BackLogCount); But when I want to stop listening, I shutdown all my clients and call m_mySocket.Close(), but it always raise a OnConnect event (actually, it calls the callback function as if there was a new connection attempt) and I receive a ObjectDisposedException as soon as I do m_mySocket.EndAccept. Does anyone have any idea of what I could do about...
11
11527
by: zgh1970 | last post by:
Hi, Friends, I need to know how to stop all database process even after db2stop. How can I stop all database processes? I have finished upgraded our system test and UAT region from 32-bit to 64-bit. I followed the following for my system test region: 1. log on aix with root 2. stop the instance 3. db2iupdt -w 64 instance
0
8673
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8601
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9156
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9021
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8892
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7716
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.