C # (asp.net) Multithreaded usage example (can be used to handle multiple tasks simultaneously) _c# Tutorial

Source: Internet
Author: User

C # (asp.net) multithreaded usage is described in this article. Share to everyone for your reference, specific as follows:

Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Threading;
Using System.Web.UI.WebControls; Public partial class Muti_thread:System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {Thr
    EAD Thread1 = new Thread (new ThreadStart (calcsum));
    Thread Thread2 = new Thread (new ThreadStart (CALCGAP));
    Thread1.start ();
    Thread2.start ();
    Thread1.join ();
  Thread2.join ();
    }//Sum method protected void Calcsum () {Long sum = 0;
      for (long i = 0; i < i++) {sum = i; Response.Write (String.
      Format ("thread1-->i={0}:sum={1}<br/>", I, sum));
      Response.Flush ();
    System.Threading.Thread.Sleep (5000);
    }///difference method protected void Calcgap () {long gap = 0;
      for (Long i = i >= 0; i--) {gap = i-1; Response.Write (String.
      Format ("thread2-->i={0}:gap={1}<br/>", I, Gap);
    Response.Flush ();  System.Threading.Thread.Sleep (1000);

 }
  }
}

Read more about C # Interested readers can view the site topics: "C # Programming Thread Usage Tips summary", "C # Common control usage Tutorial", "WinForm Control Usage Summary", "C # Data structure and algorithm tutorial" and "C # object-oriented Program Design Introductory Course"

I hope this article will help you with C # programming.

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.