RSS

Invoke On Target

12 Oct

Tired of always checking if you need to invoke or not on a thread. This method below will invoke the specified delegate on the specified target with the passed arguments.

 /// 
/// Invokes the specified delegate on the specified target with the specified arguments.
/// 
/// The delegate to invoke.
/// The target for the invocation.
/// The arguments for the invoke.
private void invokeOnTarget(Delegate del, ISynchronizeInvoke target, params object[] args)
{
    //if target requires invoke.
    if (target.InvokeRequired)
    {
        //invoke the delegate on the target
        target.BeginInvoke(del, args);
    }
    else
    {
        //invoke the delegate on this thread
        del.DynamicInvoke(args);
    }
}       
Advertisements
 
Leave a comment

Posted by on October 12, 2011 in Uncategorized

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: