0

起動する必要のある特定の数のプロセス(C#.exe)があります。優先度に応じて起動するにはどうすればよいですか。

Process.PriorityClassのことは知っていますが、プロセスの起動後にのみ優先順位が割り当てられるため、あまり役に立ちません。

私はここにこのコードを持っています(まだ優先順位を比較していません)が、プロセスが実行されていないために機能せず、プロセスに優先順位を割り当てることができません:

Process process1 = new Process();    
Process process2 = new Process();
Process process3 = new Process();

process1.StartInfo.FileName = "proc1";

process2.StartInfo.FileName = "proc2"'

process3.StartInfo.FileName = "proc3";

process1.PriorityClass = ProcessPriorityClass.AboveNormal;

process2.PriorityClass = ProcessPriorityClass.BelowNormal;

process3.PriorityClass = ProcessPriorityClass.High;

process2.Start();

process2.WaitForExit();

process1.Start();

process1.WaitForExit();

process3.Start();
4

1 に答える 1

1

プロセスファイル名を使用してディクショナリを作成し、Linqクエリを使用してOrderByを使用してProcessPriorityClassで並べ替えることができます。次に、リストを繰り返してそれらを実行し、値に適切な優先順位を割り当てます。

public void StartProcessesByPriority(Dictionary<String, ProcessPriorityClass> values)
{
    List<KeyValuePair<String, ProcessPriorityClass>> valuesList = values.ToList();

    valuesList.Sort
    (
        delegate(KeyValuePair<String, ProcessPriorityClass> left, KeyValuePair<String, ProcessPriorityClass> right)
        {
            return left.Value.CompareTo(right.Value);
        }
    );

    foreach (KeyValuePair<String, ProcessPriorityClass> pair in valuesList)
    {
        Process process = new Process();
        process.StartInfo.FileName = pair.Key;
        process.Start();

        process.PriorityClass = pair.Value;

        process.WaitForExit();
    }
}
于 2013-01-13T19:30:30.133 に答える