aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Scripting/Tango.Scripting.Basic
diff options
context:
space:
mode:
authorMirta <mirta@twine-s.com>2021-06-08 07:29:37 +0300
committerMirta <mirta@twine-s.com>2021-06-08 07:29:37 +0300
commit3b8ba4d405992661a965f2995003e1042a09c143 (patch)
treeb109da6186292b7e8d6d801620d1fb28ebefd1b1 /Software/Visual_Studio/Scripting/Tango.Scripting.Basic
parente308834f0f0d37b907db272fa10f978e4a04b8cb (diff)
parent4599616f976d1240f69d1131e0e8d97f68510132 (diff)
downloadTango-3b8ba4d405992661a965f2995003e1042a09c143.tar.gz
Tango-3b8ba4d405992661a965f2995003e1042a09c143.zip
Merge branch 'software' of https://twinetfs.visualstudio.com/Tango/_git/Tango into software
Diffstat (limited to 'Software/Visual_Studio/Scripting/Tango.Scripting.Basic')
-rw-r--r--Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs37
1 files changed, 36 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs
index 7500e404f..30fbed006 100644
--- a/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs
+++ b/Software/Visual_Studio/Scripting/Tango.Scripting.Basic/Project.cs
@@ -147,7 +147,14 @@ namespace Tango.Scripting.Basic
}
else
{
- code += Environment.NewLine + Environment.NewLine + "new Program().OnExecute(GlobalContext);";
+ if (code.Contains("OnExit(IProcedureContext context)"))
+ {
+ code += Environment.NewLine + Environment.NewLine + "var pr = new Program(); GlobalContext.OnExitAction = pr.OnExit; pr.OnExecute(GlobalContext);";
+ }
+ else
+ {
+ code += Environment.NewLine + Environment.NewLine + "new Program().OnExecute(GlobalContext);";
+ }
mainScriptCode = code;
}
}
@@ -208,8 +215,36 @@ namespace Tango.Scripting.Basic
Thread scriptThread = null;
ProjectSession<T> session = null;
+ var prop = typeof(T).GetProperty("OnExitAction");
+ bool exitActionExecuted = false;
+
session = new ProjectSession<T>(this, () =>
{
+ Action<T> onExitAction = prop?.GetValue(context) as Action<T>;
+
+ if (onExitAction != null && !exitActionExecuted)
+ {
+ exitActionExecuted = true;
+ bool completed = false;
+ DateTime startDate = DateTime.Now;
+
+ Task.Factory.StartNew(() =>
+ {
+ onExitAction(context);
+ completed = true;
+ });
+
+ while (!completed)
+ {
+ Thread.Sleep(10);
+
+ if (DateTime.Now > startDate.AddSeconds(5))
+ {
+ break;
+ }
+ }
+ }
+
scriptThread.Abort();
});