Mercurial > hg > ucis.core
diff Util/AsyncResultBase.cs @ 18:a6faa87767bb
AsyncResultBase: prevent recursive synchronous completion callback
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Wed, 10 Apr 2013 01:33:54 +0200 |
parents | 4b78cc5f116b |
children | 327be9216006 |
line wrap: on
line diff
--- a/Util/AsyncResultBase.cs Wed Apr 10 01:33:32 2013 +0200 +++ b/Util/AsyncResultBase.cs Wed Apr 10 01:33:54 2013 +0200 @@ -4,6 +4,8 @@ namespace UCIS.Util { public abstract class AsyncResultBase : IAsyncResult { + [ThreadStatic] + static Boolean ThreadInCallback = false; ManualResetEvent WaitEvent = null; AsyncCallback Callback = null; public object AsyncState { get; private set; } @@ -36,8 +38,13 @@ if (WaitEvent != null) WaitEvent.Set(); } if (Callback != null) { - if (synchronously) { - Callback(this); + if (synchronously && !ThreadInCallback) { + try { + ThreadInCallback = true; + Callback(this); + } finally { + ThreadInCallback = false; + } } else { SysThreadPool.QueueUserWorkItem(CallCallback); }