Problem using Diagnostic.Process class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

This works:
private Process oneProcess = new Process();
oneProcess.StartInfo.FileName = @"C:\oneProcess.exe";

This gets a 'System.NullReferenceException', Object reference not set to an
instance of the object:
private Process[] manyProcesses = new Process[20];
manyProcesses[0].StartInfo.FileName = @"C:\oneOfManyProcesses.exe";

What silly thing am I doing wrong?
 
Hi,

The problem is that

private Process[] manyProcesses = new Process[20];

creates an array of references to Process objects, but it does not create the
Process objects themselves. The array contains null references initially.

So manyProcesses[0] is null until you put a valid reference there.

You would need to do

manyProcesses[0] = new Process();

before you can use it.

Hope this helps.

-- Rodger

Time Management Guide - Make better use of your time
<http://www.TimeThoughts.com/timemanagement.htm>
 
Back
Top