From 65f6cfa9cf1730727cbee3dca055d3b54d83451e Mon Sep 17 00:00:00 2001 From: Michael Giagnocavo Date: Thu, 5 Jun 2008 18:15:28 +0000 Subject: [PATCH] Add auto run thread abort on hangup to AppFunction git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8768 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- .../languages/mod_mono_managed/AppFunction.cs | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/mod/languages/mod_mono_managed/AppFunction.cs b/src/mod/languages/mod_mono_managed/AppFunction.cs index 0eb6da7ccd..345e9f7109 100644 --- a/src/mod/languages/mod_mono_managed/AppFunction.cs +++ b/src/mod/languages/mod_mono_managed/AppFunction.cs @@ -46,6 +46,7 @@ namespace FreeSWITCH void hangupCallback() { Log.WriteLine(LogLevel.Debug, "AppFunction is in hangupCallback."); + abortRun(); var f = HangupFunction; if (f != null) f(); } @@ -103,6 +104,18 @@ namespace FreeSWITCH } } + protected virtual bool AbortOnHangup { get { return false; } } + bool abortable = false; + readonly object abortLock = new object(); + Thread runThread; + void abortRun() + { + if (!AbortOnHangup) return; + lock (abortLock) { + if (abortable) runThread.Abort(); + } + } + protected Guid Uuid { get; private set; } internal void RunInternal(FreeSWITCH.Native.MonoSession session, string args) @@ -112,7 +125,19 @@ namespace FreeSWITCH Session.SetDelegates(this.inputCallback, this.hangupCallback); try { this.Uuid = new Guid(Session.GetUuid()); } catch { } - Run(); + try { + runThread = Thread.CurrentThread; + lock (abortLock) abortable = true; + Run(); + } + catch (ThreadAbortException) { + Log.WriteLine(LogLevel.Debug, "Run thread aborted."); + Thread.ResetAbort(); + } + finally { + lock (abortLock) { abortable = false; } + Thread.ResetAbort(); + } } protected abstract void Run();