从C#程序类无效操作异常异常、操作、程序

由网友(不二的情书)分享简介:当我使用VSTS调试器看到类的实例进程,许多属性都标有 InvalidOperationException异常。为什么?难道我做错什么?When I use VSTS debugger to see the properties of instance of class Process, many of the pr...

当我使用VSTS调试器看到类的实例进程,许多属性都标有 InvalidOperationException异常。为什么?难道我做错什么?

When I use VSTS debugger to see the properties of instance of class Process, many of the properties are marked with InvalidOperationException. Why? Am I doing anything wrong?

我使用VSTS 2008 + C#+ NET 2.0来开发一个控制台应用程序。

I am using VSTS 2008 + C# + .Net 2.0 to develop a console application.

下面是我的code:

        System.Diagnostics.Process myProcess = new System.Diagnostics.Process();
        myProcess.StartInfo.FileName = "IExplore.exe";
        myProcess.StartInfo.Arguments = @"www.google.com";
        myProcess.StartInfo.Verb = "runas";
        myProcess.Start();

和调试器的截图:

推荐答案

要是你真正开始时,调试器拍摄照片的过程?这是我期望在开始()方法被调用来见截图。

Had you actually started the process when the debugger picture was taken? That's the screenshot I'd expect to see before the Start() method is called.

请注意,常见的模式是创建一个的ProcessStartInfo ,填充它,然后调用静态的Process.Start(StartInfo的)方法。这使得它在概念上更简单:你不看进程的对象,直到它被启动

Note that the common pattern is to create a ProcessStartInfo, populate it, and then call the static Process.Start(startInfo) method. That makes it conceptually simpler: you don't see the Process object until it's been started.