我正在尝试捕获使用ContinueWith和OnlyOnFaulted的任务方法抛出的异常,如下所示.但是,当我尝试运行此代码时,我得到一个未处理的异常.
因为我已经处理了异常,所以我希望该任务能够完成.但Task.Wait()运行到AggregateException.
var taskAction = new Action(() =>
{
Thread.Sleep(1000);
Console.WriteLine("Task Waited for a sec");
throw (new Exception("throwing for example"));
});
Task t = Task.Factory.StartNew(taskAction);
t.ContinueWith(x => Console.WriteLine("In the on Faulted continue with code. Catched exception from the task."+ t.Exception), TaskContinuationOptions.OnlyOnFaulted);
Console.WriteLine("Main thread waiting for 4 sec");
Thread.Sleep(4000);
Console.WriteLine("Wait of 4 secs complete..checking if task is completed?");
Console.WriteLine("Task State: " + t.Status);
t.Wait();
Run Code Online (Sandbox Code Playgroud)
如果我在下面的任务方法中处理异常,一切都会像我预期的那样正常.任务运行完成,异常被记录,等待也成功.
var taskAction = new Action(() =>
{
try
{
Thread.Sleep(1000);
Console.WriteLine("Task Waited for a sec");
throw …Run Code Online (Sandbox Code Playgroud) .net c# exception-handling task-parallel-library async-await
如何通过 powershell 命令找到我的服务器(windows server 2012)上安装的所有语言包?我喜欢(通过脚本)确定我的服务所需的任何语言是否未安装,然后运行 DISM 以添加缺少的语言包。