111,128
社区成员
发帖
与我相关
我的任务
分享using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using static System.Diagnostics.Process;
namespace newjob
{
public partial class Form1 : Form
{
Thread myThread;
public Form1()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
myThread = new Thread(new ThreadStart(threadCreate));
myThread.Start();
}
public void threadCreate()
{
while (true)
{
int a = GetProcessesByName("QQ").Length;
if (a > 0)
{
this.Text = "程序已在运行";
}
else
{
this.Text = "程序未运行";
}
Thread.Sleep(1000);
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
myThread.Abort();
}
private void button1_Click(object sender, EventArgs e)
{
myThread.Suspend();
}
private void button2_Click(object sender, EventArgs e)
{
myThread.Resume();
}
}
}