C#Process.Start(应用程序将代码返回给OS) [英] C# Process.Start (applications return code to OS)

查看:79
本文介绍了C#Process.Start(应用程序将代码返回给OS)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个名为AcroComm.exe的应用程序来查询我们公司的b / b
时钟。我写了一个小的C#应用​​程序,根据数据库中的信息,基于

轮询时钟。我的问题是AcroComm有时会在进程中间停止轮询并终止。该应用程序的编程说明它会在操作系统完成后发送一个代码来完成操作系统,它会告诉我们发生了什么,如下所示:


0成功

13 aborted

等...


当它中止下载时,我的程序不知道它,它只是转到下一行代码的
并继续轮询下一个时钟。我正在使用代码

,如下所示:System.Diagnostics.Process.Start(" AppPath\Name"," Command Line

Parameters")


如何挂钩并查看该流程返回到

操作系统的代码是什么?如果您需要更多信息或准确的snipet代码,请

随时问。


Anthony

I am running an application called AcroComm.exe to poll time clocks here at
our company. I have written a small C# app that will poll the clocks based
on information found in a DB. My problem is that AcroComm will sometimes
stop polling in the middle of the process and terminate. The programing
manual for the app says that it sends a code to the operating system when it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn''t know it, it just goes to
the next line of code and continues to poll the next clock. I am using code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command Line
Parameters")

How can I hook in and see what the code was that the process returned to the
operating system? If you need more info or an exact snipet of code, please
feel free to ask.

Anthony

推荐答案

Anthony,


这里有两种选择。第一个是获取Process实例并且

调用WaitForExit方法。这将阻止当前线程,直到

进程完成。


第二个选项是注册退出事件(确保设置

进程上的EnableRaisingEvents为true。


无论你决定做什么,当这些事件发生时,你可以检查

的值使用ExitCode属性来查看返回给操作系统的内容。


希望这会有所帮助。

-

- Nicholas Paldino [ .NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Tony" <关于******* @ hardenmfg.com>在消息中写道

news:eC ************** @ TK2MSFTNGP09.phx.gbl ...
Anthony,

You have two options here. The first is to get the Process instance and
call the WaitForExit method. This will block the current thread until the
process has completed.

The second option is to register for the Exited event (make sure you set
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tony" <as*******@hardenmfg.com> wrote in message
news:eC**************@TK2MSFTNGP09.phx.gbl...
我正在运行一个应用程序在我们公司调用AcroComm.exe来调查时钟。我写了一个小的C#应用​​程序,它会根据数据库中的信息来查询时钟。我的问题是,AcroComm有时会在流程中间停止轮询并终止。该应用程序的编程手册说,当它完成后,它会向操作系统发送一个代码,告诉我们发生了什么,如下所示:

0成功
13 aborted
等等...

当它中止下载时,我的程序不知道它,它只是去

下一行代码并继续轮询下一个时钟。我正在使用这样的代码
:System.Diagnostics.Process.Start(" AppPath\Name"," Command Line
Parameters")

如何挂钩并查看该过程返回到
操作系统的代码是什么?如果您需要更多信息或完整的代码,请随时询问。

Anthony
I am running an application called AcroComm.exe to poll time clocks here at
our company. I have written a small C# app that will poll the clocks based
on information found in a DB. My problem is that AcroComm will sometimes
stop polling in the middle of the process and terminate. The programing
manual for the app says that it sends a code to the operating system when
it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn''t know it, it just goes
to
the next line of code and continues to poll the next clock. I am using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command Line
Parameters")

How can I hook in and see what the code was that the process returned to
the
operating system? If you need more info or an exact snipet of code, please
feel free to ask.

Anthony


谢谢Nicholas,


我还是C#的新手...你能不能给我一个例子

或者指点我在正确的方向阅读它?

Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>写在

消息新闻:el ************** @ TK2MSFTNGP14.phx.gbl ...
Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an example
of this or point me in the right direction to read it?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:el**************@TK2MSFTNGP14.phx.gbl...
Anthony,
这里有两种选择。第一种是获取Process实例
并调用WaitForExit方法。这将阻止当前线程,直到
进程完成。

第二个选项是注册退出事件(确保
将进程上的EnableRaisingEvents设置为true) 。

无论你决定做什么,当这些事件发生时,你可以检查ExitCode属性的值,看看返回给操作系统的内容。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com

托尼 <关于******* @ hardenmfg.com>在消息中写道
新闻:eC ************** @ TK2MSFTNGP09.phx.gbl ...
Anthony,

You have two options here. The first is to get the Process instance and call the WaitForExit method. This will block the current thread until the
process has completed.

The second option is to register for the Exited event (make sure you set EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tony" <as*******@hardenmfg.com> wrote in message
news:eC**************@TK2MSFTNGP09.phx.gbl...
我正在运行一个名为AcroComm.exe的应用程序我们公司在这里查询时钟
。我写了一个小的C#应用​​程序,根据数据库中的信息轮询时钟
。我的问题是,AcroComm有时会在流程中间停止轮询并终止。该应用程序的编程手册说,当它完成后,它会向操作系统发送一个代码
,告诉我们发生了什么,如下所示:

0成功
13 aborted
等等...

当它中止下载时,我的程序不知道它,它只是去

下一行代码并继续轮询下一个时钟。我正在使用这样的代码
:System.Diagnostics.Process.Start(" AppPath\Name"," Command
Line Parameters")

如何挂钩并查看该过程返回到
操作系统的代码是什么?如果您需要更多信息或准确的snipet代码,
请随时询问。

Anthony
I am running an application called AcroComm.exe to poll time clocks here at our company. I have written a small C# app that will poll the clocks based on information found in a DB. My problem is that AcroComm will sometimes
stop polling in the middle of the process and terminate. The programing
manual for the app says that it sends a code to the operating system when it
is done that tells what has happend like the following:

0 success
13 aborted
etc...

When it aborts the downloading, my program doesn''t know it, it just goes
to
the next line of code and continues to poll the next clock. I am using
code
like this: System.Diagnostics.Process.Start("AppPath\Name", "Command Line Parameters")

How can I hook in and see what the code was that the process returned to
the
operating system? If you need more info or an exact snipet of code, please feel free to ask.

Anthony



Tony,


而不是这样做:

System.Diagnostics.Process.Start (AppPath \ Name,命令行参数);


执行此操作:


//创建流程。

using(Process process = Process.Start(" AppPath\Name"," Command Line

Parameters"))

{

//等待过程完成。

process.WaitForExit();


//在此处访问ExitCode属性从你运行的

应用程序中获取退出代码。

}

-

- Nicholas Paldino [ .NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Tony" <关于******* @ hardenmfg.com>在消息中写道

新闻:eA ************** @ tk2msftngp13.phx.gbl ...
Tony,

Instead of doing this:

System.Diagnostics.Process.Start("AppPath\Name", "Command Line Parameters");

Do this:

// Create the process.
using (Process process = Process.Start("AppPath\Name", "Command Line
Parameters"))
{
// Wait for the process to complete.
process.WaitForExit();

// Access the ExitCode property here to get the exit code from the
application you ran.
}
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tony" <as*******@hardenmfg.com> wrote in message
news:eA**************@tk2msftngp13.phx.gbl...
谢谢Nicholas,

我对C#还是比较陌生的......你能不能给我一个
这个例子,或者指出我正确的方向来阅读它?

Nicholas Paldino [.NET / C#MVP]" < mv*@spam.guard.caspershouse.com>在消息新闻中写道
:el ************** @ TK2MSFTNGP14.phx.gbl ...
Thanks Nicholas,

I am still fairly new to C#... Could you perhaps provide me with an
example
of this or point me in the right direction to read it?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:el**************@TK2MSFTNGP14.phx.gbl...
Anthony,
这里有两种选择。第一种是获取Process实例
Anthony,

You have two options here. The first is to get the Process instance


调用WaitForExit方法。这将阻止当前线程,直到
过程完成。

第二个选项是注册退出事件(确保你
call the WaitForExit method. This will block the current thread until
the
process has completed.

The second option is to register for the Exited event (make sure you


将进程上的EnableRaisingEvents设置为true)。

无论您决定做什么,当这些事件发生时,您都可以检查
的值。使用ExitCode属性来查看返回给操作系统的内容。

希望这会有所帮助。

-
- Nicholas Paldino [.NET / C#MVP]
- mv*@spam.guard.caspershouse.com

Tony <关于******* @ hardenmfg.com>在消息中写道
新闻:eC ************** @ TK2MSFTNGP09.phx.gbl ...
EnableRaisingEvents on the process to true).

Whichever you decide to do, when these events occur, you can check
the
value of the ExitCode property to see what was returned to the OS.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Tony" <as*******@hardenmfg.com> wrote in message
news:eC**************@TK2MSFTNGP09.phx.gbl...
>我正在运行一个名为AcroComm的应用程序.exe在此处轮询时间时钟>我们公司。我写了一个小型的C#应用​​程序,它将基于>轮询时钟。在数据库中找到的信息。我的问题是AcroComm会
>有时
>在流程中间停止轮询并终止。
>编程
>该应用程序的手册说它在>时向操作系统发送代码。它
>完成后会告诉我们发生了什么,如下所示:
>
> 0成功
> 13 aborted
>等...
>
>当它中止下载时,我的程序不知道它,它只是
>去
>到
>下一行代码并继续轮询下一个时钟。我正在使用
>代码
>像这样:System.Diagnostics.Process.Start(" AppPath\Name"," Command Line> Parameters")
>
>如何挂钩并查看流程返回的代码
>到
>
>操作系统?如果您需要更多信息或完整的代码,请>随便问一下。
>
> Anthony
>
>
>I am running an application called AcroComm.exe to poll time clocks here at > our company. I have written a small C# app that will poll the clocks based > on information found in a DB. My problem is that AcroComm will
> sometimes
> stop polling in the middle of the process and terminate. The
> programing
> manual for the app says that it sends a code to the operating system when > it
> is done that tells what has happend like the following:
>
> 0 success
> 13 aborted
> etc...
>
> When it aborts the downloading, my program doesn''t know it, it just
> goes
> to
> the next line of code and continues to poll the next clock. I am using
> code
> like this: System.Diagnostics.Process.Start("AppPath\Name", "Command Line > Parameters")
>
> How can I hook in and see what the code was that the process returned
> to
> the
> operating system? If you need more info or an exact snipet of code, please > feel free to ask.
>
> Anthony
>
>





这篇关于C#Process.Start(应用程序将代码返回给OS)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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