private static void InvokeCmdletMethodAndWaitForResults <T>(CmdletMethodInvoker <T> cmdletMethodInvoker, Cmdlet cmdlet) { cmdletMethodInvoker.MethodResult = default(T); try { T local = cmdletMethodInvoker.Action(cmdlet); lock (cmdletMethodInvoker.SyncObject) { cmdletMethodInvoker.MethodResult = local; } } catch (Exception exception) { lock (cmdletMethodInvoker.SyncObject) { cmdletMethodInvoker.ExceptionThrownOnCmdletThread = exception; } throw; } finally { if (cmdletMethodInvoker.Finished != null) { cmdletMethodInvoker.Finished.Set(); } } }