|
public class RaiseEventUtility
{
public static void RaiseEventAndExecuteItInTheTargetThread(System.MulticastDelegate _event, object[] _ParamArray_args)
{
if ((_event != null))
{
if (_event.GetInvocationList().Length > 0)
{
System.ComponentModel.ISynchronizeInvoke _sync = null;
foreach (System.MulticastDelegate _delegate in _event.GetInvocationList())
{
if (((_sync == null) && (typeof(System.ComponentModel.ISynchronizeInvoke).IsAssignableFrom(_delegate.Target.GetType())) && (!_delegate.Target.GetType().IsAbstract)))
{
try
{
_sync = (System.ComponentModel.ISynchronizeInvoke)_delegate.Target;
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
_sync = null;
}
}
if (_sync == null)
{
try
{
_delegate.DynamicInvoke(_ParamArray_args);
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
else
{
try
{
_sync.Invoke(_delegate, _ParamArray_args);
}
catch (System.Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}
}
}
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.