如何在.net中的另一台计算机上运行进程

Son*_*Ali 1 c# parallel-processing windows-services appdomain

假设我有一个名为"MyService"的Windows服务和一个名为"MyEXE"的可执行文件,位于我网络上的几台计算机上.

是否有可能(在"MyService"中)在不同/相同的计算机上启动"MyEXE"的几个实例,让它执行某项任务并将"true/false"结果返回到"MyService"中的回调方法?

像这样的东西

class MyService : ServiceBase
{
    delegate void UpdateCallBack(int id, bool updated)
    void CheckForUpdates()
    {
        bool updatesExist = someService.GetCurrentVersion() != currentVersion;
        if(updatesExist)
        {
            UpdatePC("C:\Program Files\MyApp.exe", 1, UpdateComplete);
            UpdatePC("\\somepc\Program Files\MyApp.exe", 1, UpdateComplete);
            UpdatePC("\\mypc\Program Files\MyApp.exe", 1, UpdateComplete);
        }
    }

    void UpdatePC(string filePath, int id, UpdateCallBack callback)
    {
       //This is where I am kind of lost 
       SomeEXERunner runner = new SomeEXERunner();
       runner.Run(filePath,"-u",id,callback);
    }

    void UpdateComplete(int id, bool updated)
    {
       //do something
       if(!updated)
          EmailService.NotifyAdmin("PC Not updated", id);
    }
}
Run Code Online (Sandbox Code Playgroud)

也许我的整个架构都错了!

Ian*_*obs 10

您可以做的一件事是在一个单独的进程中从Sysinternals 运行PsExec工具(http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx),将结果传递给一个文件,然后将其解析为数字成功/失败.