从C#程序类无效操作异常 [英] Invalid Operation Exception from C# Process Class

查看:366
本文介绍了从C#程序类无效操作异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用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.

这篇关于从C#程序类无效操作异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆