mirror of
https://github.com/TechplexEngineer/plexview.git
synced 2026-07-28 06:22:14 +00:00
Initial commit
I wish I could figure out how to have PlexVie be out of the LibOMV tree but its just not working die to a DLL not found exception about libopenjpeg. (Yes the dll is in the bin folder) This will do for now
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
// Written by Peter A. Bromberg, found at
|
||||
// http://www.eggheadcafe.com/articles/20060727.asp
|
||||
|
||||
using System;
|
||||
using System.Threading;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class ThreadUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// Delegate to wrap another delegate and its arguments
|
||||
/// </summary>
|
||||
/// <param name="d"></param>
|
||||
/// <param name="args"></param>
|
||||
delegate void DelegateWrapper(Delegate d, object[] args);
|
||||
|
||||
/// <summary>
|
||||
/// An instance of DelegateWrapper which calls InvokeWrappedDelegate,
|
||||
/// which in turn calls the DynamicInvoke method of the wrapped
|
||||
/// delegate
|
||||
/// </summary>
|
||||
static DelegateWrapper wrapperInstance = new DelegateWrapper(InvokeWrappedDelegate);
|
||||
|
||||
/// <summary>
|
||||
/// Callback used to call EndInvoke on the asynchronously
|
||||
/// invoked DelegateWrapper
|
||||
/// </summary>
|
||||
static AsyncCallback callback = new AsyncCallback(EndWrapperInvoke);
|
||||
|
||||
/// <summary>
|
||||
/// Executes the specified delegate with the specified arguments
|
||||
/// asynchronously on a thread pool thread
|
||||
/// </summary>
|
||||
/// <param name="d"></param>
|
||||
/// <param name="args"></param>
|
||||
public static void FireAndForget(Delegate d, params object[] args)
|
||||
{
|
||||
// Invoke the wrapper asynchronously, which will then
|
||||
// execute the wrapped delegate synchronously (in the
|
||||
// thread pool thread)
|
||||
if (d != null) wrapperInstance.BeginInvoke(d, args, callback, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invokes the wrapped delegate synchronously
|
||||
/// </summary>
|
||||
/// <param name="d"></param>
|
||||
/// <param name="args"></param>
|
||||
static void InvokeWrappedDelegate(Delegate d, object[] args)
|
||||
{
|
||||
d.DynamicInvoke(args);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Calls EndInvoke on the wrapper and Close on the resulting WaitHandle
|
||||
/// to prevent resource leaks
|
||||
/// </summary>
|
||||
/// <param name="ar"></param>
|
||||
static void EndWrapperInvoke(IAsyncResult ar)
|
||||
{
|
||||
wrapperInstance.EndInvoke(ar);
|
||||
ar.AsyncWaitHandle.Close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user