【问题标题】:IHttpActionResult timeout while waiting for for powershell script等待 powershell 脚本时 IHttpActionResult 超时
【发布时间】:2017-03-23 15:08:11
【问题描述】:

我需要做类似的事情:

public IHttpActionResult StartArchiving(string machineName)
{
    //Email users to notice them an archiving started on their machine 
    EmailHelper.SendEmail(some params);

    //powershell scripting call could extends up to 2-3 hours maybe
    var answere = PowerShell.Archive(machineName);

    //Email users to notice them the archiving has stopped on their machine
    EmailHelper.SendEmail(some params);
}

发送第一封邮件后,任务可以持续很长时间。 完成 Powershell 脚本后,C# 任务将继续运行并发送第二封电子邮件,否则任务将停止且不发送电子邮件。

【问题讨论】:

    标签: c# powershell timeout


    【解决方案1】:

    听起来您需要“异步”执行 Powershell.Archive() 调用,这意味着您的其余代码将立即继续运行,而无需等待 Powershell.Archive() 完成。我建议阅读如何使用 C# 中的“async”和“await”关键字进行异步编程。

    【讨论】:

      猜你喜欢
      • 2016-02-15
      • 1970-01-01
      • 2012-04-19
      • 2012-09-20
      • 1970-01-01
      • 2016-09-01
      • 2015-02-02
      • 1970-01-01
      • 2013-10-23
      相关资源
      最近更新 更多