複数のプロセスが閉じたときにコンピューターをシャットダウンする自動シャットダウン アプリケーションを作成しようとしています。
例: ユーザーは、現在実行中のすべてのプロセスを一覧表示するチェックリスト ボックスを持っています。ユーザーのチェックは、監視したいすべてのプロセスにマークを付けます。これらのプロセスがすべて閉じられると、コンピューターはシャットダウンすることになっています。これを行うのに問題があります。チェックしたプロセス項目が閉じているかどうかをプログラムにチェックさせる方法がわかりません。これが私が今持っているコードです。誰かが私に与えることができるすべての助けに感謝します。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private int counter;
Process[] p = Process.GetProcesses();
private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 100;
foreach (Process plist in p)
{
checkedListBox1.Items.Add(plist.ProcessName);
}
}
private void timer1_Tick(object sender, EventArgs e)
{
counter = 0;
checkedListBox1.Items.Clear();
Process[] p = Process.GetProcesses();
foreach (Process plist in p)
{
checkedListBox1.Items.Add(plist.ProcessName);
counter = counter + 1;
}
if (counter == 0)
{
MessageBox.Show("works");
}
}
private void button1_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
timer1.Start();
}
}
}
ありがとう、
-エンジェル・メンデス