I am trying to understand why this works ...
using (Process ProcRegEdit = Process .Start("REGEDIT.EXE", "/s
C:\\Ajay\\VS2005\\C#\\REGISTRY\\ajay.reg"))
{
ProcRegEdit.WaitForExit(); // Wait indefinitely
if (ProcRegEdit.HasExited)
{
ProcRegEdit.Close();
}
... but this does not.
using (Process ProcRegEdit = new Process())
{
ProcRegEdit.Start("REGEDIT.EXE", "/s
C:\\Ajay\\VS2005\\C#\\REGISTRY\\ajay.reg");
ProcRegEdit.WaitForExit(); // Wait indefinitely
if (ProcRegEdit.HasExited)
{
ProcRegEdit.Close();
}
}
/* NOTES
This line ...
ProcRegEdit.Start("REGEDIT.EXE", "/s
C:\\Ajay\\VS2005\\C#\\REGISTRY\\ajay.reg");
... generates a build error with the following message
Static member 'member' cannot be accessed with an instance reference;
qualify it with a type name instead
*/
Thanks.
Jon Skeet [C# MVP] - 11 Mar 2008 09:43 GMT
> I am trying to understand why this works ...
<snip>
> This line ...
>
[quoted text clipped - 5 lines]
> Static member 'member' cannot be accessed with an instance reference;
> qualify it with a type name instead
You've used ProcRegEdit.Start instead of Process.Start. You aren't
allow to try to use a static member (which Start is) as an instance
member - it can lead to confusion and very misleading code.
As a side note, it would be clearer which calls were static and which
were instance if you'd use camel case for your variable - procRegEdit
instead of ProcRegEdit.

Signature
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
Roger Frost - 11 Mar 2008 09:56 GMT
> [...]
>
[quoted text clipped - 9 lines]
>
>[...]
The general idea behind a static member is to have a helper method that
doesn't need an instance in memory to do it's job. You can think of them as
synonymous to library routines. They are members of the Class and not the
Object.
In your case that works, you are starting regedit in a new process and
giving that process a friendly name.
In your case that does not work, you are (in logic) creating a process then
trying to start regedit in it. But regedit (or whatever the case may be)
needs it's own process.
It's a bit more complicated but this is the basic idea.

Signature
Roger Frost
"Logic Is Syntax Independent"
AA2e72E - 11 Mar 2008 10:18 GMT
Thanks for the explanations.
I think with the statement <they are members of the Class and not the Object
> I chave grasped the implications.