Concurrency in csharp (Asynchronous, Parallel, and Multithreaded Programming), concurrencycsharp

Source: Internet
Author: User

Concurrency in csharp (Asynchronous, Parallel, and Multithreaded Programming), concurrencycsharp

Http://stephencleary.com/projects/

 

/// <Summary> ///// </summary> public partial class Form2: Form {// [ComVisible (false)] // public delegate void ParameterizedThreadStart (object objfield); // <summary> //// </summary> public Form2 () {InitializeComponent ();} /// <summary> //// </summary> /// <param name = "sender"> </param> /// <param name = "e "> </param> private void Form2_Load (object sender, eventArgs e) {MyDu du = new MyDu (); Control. checkforillegalcrossthreadcils = false; Thread t1 = new Thread (new ThreadStart (TestMethod); Thread t2 = new Thread (new ParameterizedThreadStart (TestMethod )); // Thread t3 = new Thread (new ThreadStart (du. setData); ThreadPool. queueUserWorkItem (new WaitCallback (TaskProc1), new Person {Id = 1, Name = "test", Count = 100}); du. begID = 100; du. endID = 20000; du. le1 = this. label3; du. le2 = this. label4; Thread t3 = new Thread (new ThreadStart (du. run); t1.IsBackground = true; t2.IsBackground = true; t3.IsBackground = true; t1.Start (); t2.Start ("hello"); t3.Start ();} /// <summary> ///// </summary> /// <param name = "x"> </param> public void TaskProc1 (object x) // The executed task {Person person = x as Person;} // private delegate void InvokeCallback (string msg); // private delegate void SetLabelDelegate (string value ); /// <summary> ///// </summary> void TestMethod () {// InvokeCallbackmsgCallback = new InvokeCallback (m_comm_MessageEvent); string v = "geovind du 1 "; this. label1.Text = v; // if (this. invokeRequired) // {// SetLabelDelegate d = new SetLabelDelegate (TestMethod); // this. invoke (d, new object [] {v}); //} // else // {// this. label1.Text = v; //} void TestMethod (object data) {if (this. invokeRequired) {SetLabelDelegate d = new SetLabelDelegate (TestMethod); this. invoke (d, new object [] {data});} else {string datastr = data as string; this. label2.Text = datastr ;}} public class Person {public int Id {get; set;} public string Name {get; set ;}public int Count {get; set ;}} /// <summary> ///// </summary> class MyDu {private int begID; public int BegID {set {this. begID = value ;}} private int endID; public int EndID {set {this. endID = value ;}} private Label le1; public Label Le1 {set {this. le1 = value ;}} private Label le2; public Label Le2 {set {this. le2 = value ;}/// <summary> //// </summary> public void Run () {method (begID, endID, le1, le2 );} /// <summary> ///// </summary> /// <param name = "begin"> </param> /// <param name = "end "> </param> private void method (int begin, int end, Label labe, Label labe2) {labe. text = begin. toString (); labe2.Text = end. toString ();}}}

  

Related Article

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.