C # delegate base 9--invoke and delegates

Source: Internet
Author: User

C # commissioned the basic series was originally published in February 2011 in my Sina blog, now it will be like this blog.

Example One

delegate void Appendstringcallback (string text);

private void appendstring (string txt)
{
     this.listView1.Items.Add (TXT);
}

 

private void Receivedate ()

{

     Appendstringcallback appendstringcallback = new Appendstringcallback ( appendstring);

     This. Invoke (Appendstringcallback, new object[] {string. Format ("{0},{1},{2}", str1, str2

                 + "number", Iepaddress.tostring ())});




Case II

namespace ThreadPoolDemo {public partial class Threadform:form {//define delegate to use when invoke   
       

        Private delegate void Setprogressbarvalue (int value); The method that matches the Setprogressbarvalue delegate is private void Setprogressvalue (int value) {Progressbar.val  
       UE = value; ////using the Invoke method to set the progress bar private void Runwithinvoke () {int value = PROGRESSBAR.V  
            Alue;  
                while (value< progressbar.maximum) {//if (invokerequired) is invoked across threads {this.  
                Invoke (New Setprogressbarvalue (Setprogressvalue), value++);  
                else {progressbar.value = ++value;  
        }} public Threadform () {InitializeComponent (); } private void BTNinvoke_click (object sender, EventArgs e) {progressbar.value = 0;  
            Thread thread = new Thread (new ThreadStart (Runwithinvoke)); Thread.  
        Start ();

 }   

     }  
}

This article refers to the content of the agent from Jin Xu-liang's ". NET 4.0 object-oriented Programming"


Details can refer to my Sina blog http://blog.sina.com.cn/s/blog_67aaf4440100omf1.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.