C # Beginlnvoke Delegate

Source: Internet
Author: User

Using system;using system.collections.generic;using system.componentmodel;using system.data;using System.Drawing; Using system.linq;using system.text;using system.windows.forms;namespace windowsformsapplication1{public partial        Class Form1:form {public delegate void Deletask (int num1, int num2);        Public Form1 () {InitializeComponent ();            } private void Button1_Click (object sender, EventArgs e) {deletask task = new Deletask (test); int num30 = Int.            Parse (This.textBox1.Text); int num40 = Int.            Parse (This.textBox2.Text); Task.        BeginInvoke (NUM30, NUM40, NULL, NULL);            } private void Test (int num1, int num2) {int sum = 0;                for (int i = NUM1; I <= num2; i++) {sum + = NUM1;            num1++; } this.label1.Text = Sum.        ToString ();     private void Form1_Load (object sender, EventArgs e)   {control.checkforillegalcrossthreadcalls = false; }    }}

C # Delegate thread return value using system;using system.collections.generic;using system.componentmodel;using system.data;using    System.drawing;using system.linq;using system.text;using system.windows.forms;namespace WindowsFormsApplication1{        Public partial class Form1:form {public delegate int deletask (int num1, int num2);        Public Form1 () {InitializeComponent ();            } private void Button1_Click (object sender, EventArgs e) {deletask task = test; int num3 = Int.            Parse (This.textBox1.Text); int num4 = Int.            Parse (This.textBox2.Text); Task.            BeginInvoke (num3, num4, NULL, NULL); IAsyncResult res = task.            BeginInvoke (num3, num4, NULL, NULL); int result = task.            EndInvoke (RES); This.label1.Text = result.        ToString ();            } private int Test (int num1, int num2) {int sum = 0; for (int i = NUM1; I <= num2; i++) {sum + = nUM1;            num1++;        } return sum;  private void Form1_Load (object sender, EventArgs e) {control.checkforillegalcrossthreadcalls =        False }    }}

  

C # Beginlnvoke Delegate

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.