forked from Mirrors/freeswitch
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
This commit is contained in:
parent
2602ad6cba
commit
65f6cfa9cf
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user