来自 C# 进程类的无效操作异常 [英] Invalid Operation Exception from C# Process Class

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

问题描述

当我使用 VSTS 调试器查看 Process 类实例的属性时,许多属性都被标记为 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.

这是我的代码:

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();

以及调试器的截图:

推荐答案

在拍摄调试器图片时,您是否真的开始了这个过程?这是我希望在调用 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) 方法.这使得它在概念上更简单:在 Process 对象启动之前,您不会看到它.

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天全站免登陆