C # multithreading and GDI (Day 23)

Source: Internet
Author: User

C # multithreading and GDI (Day 23)
Theory: before learning multithreading, first understand what processes are? Process: (Keyword: Process) a Process is a running activity of a program with certain independent functions about a data set. It is the basic unit of dynamic execution in the operating system. In traditional operating systems, processes are both basic allocation units and basic execution units. Simply put, it is a running software started by a computer, and it is the execution process of a program. The operating system contains N processes. A process contains multiple threads. threads: (keyword Thread) a Thread is a single sequential control process in a program. Multiple Functions are opened in a process to execute multiple tasks at the same time. Each program has at least one thread. If the program has only one thread, it is the program itself. Front-end thread: the UI interface uses the default front-end thread. After the front-end thread is terminated, the background thread will not be terminated. Background thread: After the background thread of the custom thread object is terminated, the foreground thread will end. Multithreading: multiple threads are run in a single program at the same time to complete different tasks and become multiple threads. GDI: Graphical Device Interface (GDI: Graphics Device Interface) is a Windows subsystem that displays Graphics on video monitors and printers. Actual Operation: process (in the console) <strong> <span style = "font-size: 18pt;"> class Program {static void Main (string [] args) {Process [] proce = Process. getProcesses (); // obtain all processes on the operating system foreach (var item in proce) {item. kill (); // stop the associated process (use with caution) Console. writeLine (item);} Process. start ("devenv"); // open a Process p1 = new Process (); // instantiate a Process ProcessStartInfo info = new ProcessStartInfo (@ "C: \ Windows \ system32 \ calc.exe "); // enable the meter The path of the computer process is p1.StartInfo = info; p1.Start (); // open }}</span> </strong> thread: design the Interface main code in the Form: <strong> <span style = "font-size: 18pt;"> public partial class Form1: Form {public Form1 () {InitializeComponent ();} bool B = false; thread th = null; // introduce the namespace private void button#click (object sender, EventArgs e) {Control. checkforillegalcrossthreadcils = false; // whether to cross-thread if (! B) {this. button1.Text = "Terminate"; B = true; th = new Thread (Bgian); th. start (); // Start} else {this. button1.Text = "Lucky Draw"; B = false; th. abort (); // terminate thread} public void Bgian () {// Let the three label controls cyclically obtain the Random number Random r = new Random (); while (true) {label1.Text = r. next (1, 10 ). toString (); label2.Text = r. next (1, 10 ). toString (); label3.Text = r. next (1, 10 ). toString () ;}}</span> </strong> running result, click the "Lucky Draw" button. Click the "Terminate" button to display the following interface: GDI drawing (straight line) <strong> <span style = "font-size: 18pt;"> public partial class Form1: form {public Form1 () {InitializeComponent ();} private void button#click (object sender, EventArgs e) {Graphics g = this. createGraphics (); // introduce the namespace using System. drawing; Pen p = new Pen (Brushes. red); // Pen defines the object Brushes used to draw straight lines and curves for all standard colors of the paint brush g. drawLine (p, new Point (100,100), new Point (300,100); // you can draw only one line Point. [] Points = {new Point (150,200), new Point (250,200), new Point (100,300), new Point (300,300 )}; // define a Point array to draw multiple lines. drawLines (p, points) ;}</span> </strong> serialization: serialization stores classes on hard disks in binary format. Keyword: BinaryFormater. Define a serialization: BinaryFormatter binary = new BinaryFormatter ();

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.