[Freeswitch-svn] [commit] r8768 - freeswitch/trunk/src/mod/languages/mod_mono_managed

Freeswitch SVN michaelgg at freeswitch.org
Thu Jun 5 14:15:29 EDT 2008


Author: michaelgg
Date: Thu Jun  5 14:15:28 2008
New Revision: 8768

Modified:
   freeswitch/trunk/src/mod/languages/mod_mono_managed/AppFunction.cs

Log:
Add auto run thread abort on hangup to AppFunction


Modified: freeswitch/trunk/src/mod/languages/mod_mono_managed/AppFunction.cs
==============================================================================
--- freeswitch/trunk/src/mod/languages/mod_mono_managed/AppFunction.cs	(original)
+++ freeswitch/trunk/src/mod/languages/mod_mono_managed/AppFunction.cs	Thu Jun  5 14:15:28 2008
@@ -46,6 +46,7 @@
         void hangupCallback()
         {
             Log.WriteLine(LogLevel.Debug, "AppFunction is in hangupCallback.");
+            abortRun();
             var f = HangupFunction;
             if (f != null) f();
         }
@@ -103,6 +104,18 @@
             }
         }
 
+        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 @@
             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();



More information about the Freeswitch-svn mailing list