C # Multithreading and GDI (day 23)

Source: Internet
Author: User

Again came to summarize the knowledge of the time, and today learned some new knowledge, multithreading and GDI some of the use.

Theory:

Before learning multithreading, you should first understand what is a process?

Process: The(keyword process) process is a running activity of a program with a certain set of functions about a data collection. It is the basic unit of the operating system dynamic execution, in the traditional operating system, the process is not only the basic allocation unit,

is also the basic execution unit. In a nutshell, a running software that is opened by a computer is the process of executing 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 that creates multiple functions within a process to perform multiple tasks at the same time . Each program has at least one thread, and if the program has only one thread, it is the program itself .

Foreground thread:The UI interface uses the system to give us the default foreground thread after the foreground thread terminates, the background thread does not terminate.

Background thread: The foreground thread will end when the background thread of our custom thread object terminates.

Multithreading : running multiple threads at the same time in a single program completes different tasks to become multithreaded. GDI: Graphics Device interfaces (Gdi:graphics device Interface) is a subsystem of windows that is responsible for displaying graphics on video displays and printers.

Real:

Process (under Console)

Class program    {        static void Main (string[] args)        {            process[] proce = process.getprocesses ();  Gets all processes on the operating system            foreach (var item in Proce)            {                 item. Kill ();                        Stop the associated process (with caution)                Console.WriteLine (item);            }              Process.Start ("devenv");          Opening a process              P1 = new process ();      Instantiate a process              processstartinfo info = new ProcessStartInfo (@ "C:\Windows\system32\calc.exe");//Open the path of the calculator process              P1. StartInfo = info;                      P1. Start ();                 Open        }}}    

Threads: Under the Form form

Design interface

Main code:

Public partial class Form1:form {public Form1 () {InitializeComponent ();        } bool B = false;   Thread th = null; Introduce namespace private void Button1_Click (object sender, EventArgs e) {control.checkforillegalcrossth  Readcalls = false;                                Whether to cross-thread if (!b) {this.button1.Text = "terminate";                B = true;                 th = new Thread (Bgian); Th.    Start ();                   Start} else {this.button1.Text = "lottery";                   b = false; Th.    Abort ();  Terminate thread}} public void Bgian () {//Let three label controls loop to get the random number of 1--10            = 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 (); }                      }    }

Run results

The interface that appears when you click the "Draw" button

The interface that appears when you click the Terminate button:

GDI drawing (Straight line)

public partial class Form1:form    {public        Form1 ()        {            InitializeComponent ();        }        private void Button1_Click (object sender, EventArgs e)        {            Graphics g = this. CreateGraphics (); Introduction of namespaces using System.Drawing;            Pen p = new Pen (brushes.red);      The pen defines the brush G.drawline (p,new point (100,100), the new Point (300,100)) that is used to draw the lines and curves of the object   brushes all standard colors            ;//Only one line can be drawn Point[] points = {new Point (at five), New Point (+), new Point (                     300, 300)};//defines a point array To draw multiple lines            G.drawlines (p, points);              }

Simply mention serialization: serialization is the process of saving a class in binary form on a hard disk. The keyword is: binaryformater. The definition of a serialization is: BinaryFormatter binary = new BinaryFormatter ();

Well, I'll write about it here today. It's going to be next week. Come on!

C # Multithreading and GDI (day 23)

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.