From 17abbf35ba72283c6dab9135f1e75b7057371431 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 20 Apr 2020 07:22:48 +0300 Subject: Scripting.. --- .../Scripting/Tango.Scripting.Basic/ProjectSession.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs') diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs index a613f2bcc..565949402 100644 --- a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs +++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/ProjectSession.cs @@ -9,6 +9,7 @@ namespace Tango.Scripting.Basic public class ProjectSession { private Action _abortAction; + private TaskCompletionSource _completion; public event EventHandler StateChanged; @@ -18,6 +19,7 @@ namespace Tango.Scripting.Basic public ProjectSession(Project project, Action abortAction) { + _completion = new TaskCompletionSource(); Project = project; _abortAction = abortAction; } @@ -26,24 +28,27 @@ namespace Tango.Scripting.Basic { _abortAction(); State = ProjectSessionState.Aborted; + _completion.SetException(new OperationCanceledException("Project execution aborted.")); RaiseStateChanged(); } internal void Failed(Exception ex) { State = ProjectSessionState.Failed; + _completion.SetException(ex); RaiseStateChanged(null, ex); } internal void Completed(object returnValue) { State = ProjectSessionState.Completed; + _completion.SetResult(returnValue); RaiseStateChanged(returnValue, null); } private void RaiseStateChanged(object returnValue = null, Exception ex = null) { - StateChanged?.Invoke(this, + StateChanged?.Invoke(this, new ProjectSessionStateChangedEventArgs() { ReturnValue = returnValue, @@ -51,5 +56,10 @@ namespace Tango.Scripting.Basic Exception = ex }); } + + public Task WaitForCompletion() + { + return _completion.Task; + } } } -- cgit v1.3.1