| |

VerySource

 Forgot password?
 Register
Search
View: 686|Reply: 3

How to tell if a process exists?

[Copy link]

2

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-1-22 13:20:01
| Show all posts |Read mode
How to tell if a process exists? Close if it exists.
HasExited method of the process do not know how to use, solve
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 Invalid IP Address

Post time: 2020-2-4 13:00:01
| Show all posts
processes pros = Process.GetProcesses ();
Process pro = Process.GetCurrentProcess ();

foreach (Process p in pros)
{
   if (p.MainWindowTitle == pro.MainWindowTitle)
   {
     // exit the program
   }
}
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-2-5 06:45:02
| Show all posts
using System.Diagnostics;

Process [] proc = Process.GetProcessesByName ("ProcessName");
if (proc.Length == 0)
{
    //does not exist...
}
Reply

Use magic Report

0

Threads

56

Posts

21.00

Credits

Newbie

Rank: 1

Credits
21.00

 China

Post time: 2020-2-5 07:30:02
| Show all posts
Connect
else
{
   foreach (Process process in proc)
       process.Kill ();
}
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list