qq_36918522
Fairy-HE
2017-12-09 12:30

C#计算器的进程不能关闭

5
  • c#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Diagnostics;
using System.IO;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void button1_Click(object sender, EventArgs e)
    {
        process1.Start();
    }

    private void button2_Click(object sender, EventArgs e)
    {
        FileInfo file = new FileInfo(@"C:\Windows\System32\calc.exe");
        if (file.Exists)
        {
            Process proc = new Process();
            proc.StartInfo.FileName = file.FullName;
            proc.Start();
        }
    }

    private void button3_Click(object sender, EventArgs e)
    {
        Process[] cp;
        cp = Process.GetProcessesByName("calc");

        //cp = Process.GetProcessesByName("calc.exe");
        int i = cp.Length;
        foreach (Process instance in cp)
        {
            instance.Close();
        }
    }
}

}

有两个启动计算器的按钮,一个关闭所有计算器进程的按钮,关闭的按钮获取不到计算器的进程为什么呢

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

5条回答

为你推荐

换一换