C # thread call,

Source: Internet
Author: User

C # thread call,

I. Advantages of threads

1. When the server is under normal load, the thread can improve the efficiency;

2. If the code executed by a thread fails, the main program will not be affected, improving program stability and reliability.

 

Ii. Thread creation and common attributes

1. Thread Creation

ThreadStart ts1 = new ThreadStart (function2); // thread-defined execution

Thread t1 = new Thread (ts1 );

T1.Start ();

Or

Thread t1 = new Thread (new ThreadStart (function2 ));

T1.Start ();

2. Common attributes of threads

Priority get or set, thread Priority

IsBackgroud gets or sets whether it is a background thread

Abort (): Terminate the thread

Start () Start thread

3. program instance

Using System;
Using System. Collections. Generic;
Using System. Linq;
Using System. Text;
Using System. Threading;

Namespace Thread2
{
Class Program
{
Static void function1 ()
{
For (int I = 0; I <40; I ++)
{
Console. WriteLine (I );
}
}
Static void function2 ()
{
For (int I = 41; I <200; I ++)
{

Console. WriteLine (I );
Int c = 2;
Int x = 0;
Int y = c/x;
}
}
Static void function3 ()
{
For (int I = 200; I <205; I ++)
{
Console. WriteLine (I );
// Int c = 2;
// Int x = 0;
// Int y = c/x;


}
}
Static void Main (string [] args)
{
Console. WriteLine ("Main begin! ");

ThreadStart ts = new ThreadStart (function1); // thread-defined execution
Thread t = new Thread (ts );
T. Priority = ThreadPriority. Highest;
T. Start ();

Console. WriteLine ("Main end! ");

ThreadStart ts1 = new ThreadStart (function2); // thread-defined execution
Thread t1 = new Thread (ts1 );
// T1.Priority = ThreadPriority. Highest;
// T1.IsBackground = true; // exit even if the main program is not executed
T1.Start ();

Function3 (); // directly execute

Console. WriteLine ("Main1111 end! ");
}


}
}

 


C language ^ how to use

A1 = 0x01; // 0000 0001
A2 = 0x00; // 0000 0000
A3 = 0x03; // 0000 0011
A4 = 0x02; // 0000 0010

B1 = a1 ^ a2; // 0000 0001
B2 = a1 ^ a3; // 0000 0010
B3 = a1 ^ a4; // 0000 0011

^ XOR operator. The bitwise value is 0 and the difference is 1. See the example above.

//
Examples of simple and practical problems:
====================================
======= A ======= B =========
There are two circuits on the top. The two switches are a and B respectively. The opening status is \ [1], and the closing status is/[0].
If both circuits are enabled or disabled.
If a turns on [1], B turns off [0], and circuit 1 Powers on
=====================
If a disables [0], B enables [1], and circuit 2 powers on.
====================================
In summary, the circuit fails in the and B states simultaneously [0]. When a and B are different, the power is charged [1].

Symbol in C Language <Yes

Left shift operator (<)

Removes all the binary bits of an operation object from the left and adds 0 to the right ).

For example, a = a <2 shifts the binary bits of a two places to the left and complements 0 to the right,

Move 1 to the left and then a = a * 2;

If the left shift does not include 1 in the Discard high position, then shifts one bit left, which is equivalent to multiplying the number by 2.
Shift right operator (>)

Shifts all the binary bits of a number to several places to the right, and adds 0 to the left of the positive number, 1 to the left of the negative number, and discards the right of the negative number.

The operand shifts one digit to the right, which is equivalent to dividing the number by 2.

For example, a = a> 2 shifts the binary bit of a two places to the right,

0 or 1 to see whether the number is positive or negative.

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.