开发者

How to use .net System.Diagnostics::Process OnExited C++?

Can anyone please give an example how to use the OnExited event in C++开发者_开发问答, see link form msdn which one I'm referring to. http://msdn.microsoft.com/en-us/library/system.diagnostics.process.onexited.aspx . I am really confused with this C++/CLI. I am trying to delete a file after the process exited. I got it working in C# but prefer C++ so it can be easier to be wrapped for JNI.


I'm not really sure what you want, so here's a literal translation of the code on the page you linked to from C# to C++/CLI:

using namespace System;
using namespace System::Diagnostics;

ref class MyProcess : public Process
{
public:
    void Stop()
    {
        this->CloseMainWindow();
        this->Close();
        OnExited();
    } 
};

void myProcess_HasExited(Object^ sender, EventArgs^ e)
{
    Console::WriteLine(L"Process has exited.");
}

int main(array<String^>^ args)
{
    MyProcess^ p = gcnew MyProcess();
    p->StartInfo->FileName = L"notepad.exe";
    p->EnableRaisingEvents = true;
    p->Exited += gcnew EventHandler(myProcess_HasExited);
    p->Start();
    p->WaitForInputIdle();
    p->Stop();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜