Lesson 7:c# Multithreading

Source: Internet
Author: User

C # Multithreading

1. Applicable to:

Communication over the network

Perform time-consuming actions

Differentiate tasks with different priorities

Enables the user interface to respond quickly to user interactions when performing background tasks

2. common attributes and methods of Thread class

Property:

IsAlive: Show current thread execution status

IsBackground: Whether it is a background process

Name: Gets or sets the thread name

ThreadState: Gets the current thread state

Method:

Thread: constructor, delegate passed to thread when thread is started

Abort: When called, ThreadAbortExceptionis raisedand the thread begins to terminate

Join: blocks the calling thread until a thread terminates

ResetAbort: Cancels abort of the current thread request

Sleep: Sets the number of milliseconds that the thread blocks specified

Start: Begin execution

3, the status of the thread:

4. Start Thread:

1) Create a thread instance:

As shown, invoking the constructor method of the thread class instantiates a thread instance, but the actual thread is not created, at which point the thread is in the unstarted state.

Create thread instances Common: thread t = new Thread (threading method);

and delegate the thread instance to the method of executing the thread: Void Thread method () | | void Threading Method (object)

2) Create thread

T.start ();

T.start (Object obj);

5. Suspend Thread:

thread.sleep (1000);

6. Merging Threads:

You can call the Join method in T1 code if one thread T1 during execution and needs to wait for another thread to finish T2 to continue execution.

For example: T2. Join ();

7. Terminating the thread:

forcibly terminating a thread:. Abort ()

Natural Termination : When the delegate method ends, the thread ends with it.

Cond...

Lesson 7:c# Multithreading

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.