invoke delegate with parameters

Download Ping Example Code (10kb)

The following is a simple code to invoke a delegate with parameter. I created this to update label control on the form asynchronously. I did not quite work I was hoping for but the code does pass parameter to the delegate

private void Ping_Click(object sender, EventArgs e)
    BeginInvoke(new InvokeDelegate(UpdateLabelAsych),"test");

    Ping ping = new Ping();
    PingReply pingresult = ping.Send(txtIpAddress.Text);
    if (pingresult.Status.ToString() == "Success")
        BeginInvoke(new InvokeDelegate(UpdateLabelAsych), "Success");
        BeginInvoke(new InvokeDelegate(UpdateLabelAsych), "Failure");

private void UpdateLabelAsych(string msg)
    label1.Text = msg;

private delegate void InvokeDelegate(string s);
This entry was posted in Tutorials/Tips and tagged , , , . Bookmark the permalink.

1 Response to invoke delegate with parameters

  1. Pingback: Software Development Blog » favicon not showing

Leave a Reply

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

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

Google photo

You are commenting using your Google 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 )

Connecting to %s