From 584c1138361c6c5ed3ad18225760fb5f9e88093a Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Tue, 1 Sep 2009 11:26:08 -0700 Subject: Added Util.FireAndForget(), to replace leaking calls to Delegate.BeginInvoke() --- OpenSim/Framework/Util.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'OpenSim') diff --git a/OpenSim/Framework/Util.cs b/OpenSim/Framework/Util.cs index bbb0ae2..58344f3 100644 --- a/OpenSim/Framework/Util.cs +++ b/OpenSim/Framework/Util.cs @@ -1169,5 +1169,27 @@ namespace OpenSim.Framework return found.ToArray(); } + + #region FireAndForget Threading Pattern + + public static void FireAndForget(System.Threading.WaitCallback callback) + { + callback.BeginInvoke(null, EndFireAndForget, callback); + } + + public static void FireAndForget(System.Threading.WaitCallback callback, object obj) + { + callback.BeginInvoke(obj, EndFireAndForget, callback); + } + + private static void EndFireAndForget(IAsyncResult ar) + { + System.Threading.WaitCallback callback = (System.Threading.WaitCallback)ar.AsyncState; + + callback.EndInvoke(ar); + ar.AsyncWaitHandle.Close(); + } + + #endregion FireAndForget Threading Pattern } } -- cgit v1.1