Multi-threaded learning and GDI learning

Source: Internet
Author: User

today is a week of Friday, feel good fast, I feel not looking forward to the weekend, but the feeling is now accustomed to sitting here every day to knock code, in fact, I am a very cheerful personality of the girls, now do not know why Feel silently sitting in their own position above the code became I am accustomed to things, although there is no such thing, but I feel I have to master a lot of ah, now just beginning, follow the teacher's pace slowly in the progress, but too much knowledge of the master or rely on their own understanding, Now is the feeling too much do not understand the knowledge, is not the beginning of anxiety I do not know, but I will work hard. Hey, today we learn multithreading and GDI, summarized below.

I. Multi-Threading

Before we learn multithreading we need to know two nouns, processes and threads:

    • Process: Yes a running software that is turned on by a computer is called a process on our operating system. A computer has n processes;
    • Threading: Refers to the creation of multiple functions in a process to perform multiple tasks at the same time.

A process contains multiple threads, the threads work at the same time, and an application has only one process; we need to use the process class for the duration of the course.

        Static voidMain (string[] args) {            #regionMyregion//Process.Start ("devenv"); //Open vs through the process, and the parameter in the Start method is the name of the process            #endregion            #regionMyregion//process[] Process = process.getprocesses (); //here is all the process of opening the computer above//foreach (var item in process)//{            //Console.WriteLine (item); //}            #endregion            #regionMyregion//process P = new process (); //ProcessStartInfo info = new ProcessStartInfo (@ "C:\Program Files (x86) \tencent\qq\qqprotect\bin\qqprotect.exe");//instantiate an object in the ProcessStartInfo class and pass the path to the open process//P.startinfo=info; //P.start (); //Open a process//Console.readkey ();            #endregion          }

The above mainly learn the process of the method, the following simple method of learning the thread, and the threading method uses thread this class, Xiamin create a WinForm form, drag a TextBox and button in it, as follows:


Private voidBtn_click (Objectsender, EventArgs e) {Control.checkforillegalcrossthreadcalls=false; /*Control (the parent class of the WinForm control), where his method is called, the method means whether to cross the thread, let him set to false, when the form that is displayed without adding this method time is called console (console) Time WinForm form cannot be used, only Only the console is in the count;*/Thread th=NewThread (Ran);//Thread Instantiation ObjectTh. Start ();//Call method Start        }         Public voidRan ()//number of loops between 0 and 1000        {             for(inti =0; I < +; i++)            {                 This. TextBox1.Text =i.tostring (); }        }

in the example of the use of a thread, in life we often see the lottery machine, below we will simply make a small lottery machine, hey, the code is as follows:


 Public Partial classForm1:form { PublicForm1 () {InitializeComponent (); }        BOOLb =false; Thread T=NULL; Private voidButton1_Click (Objectsender, EventArgs e) {            if(!b) { This. button1. Text ="Stop"; b=true; Control.checkforillegalcrossthreadcalls=false; T=NewThread (Ran);            T.start (); }            Else            {                 This. button1. Text ="Lottery"; b=false;            T.abort (); }        }         Public voidRan () {Random R=NewRandom ();  while(true)            {                 This. label4. Text = R.next (0,Ten).                ToString ();  This. Label2. Text = R.next (0,Ten).                ToString ();  This. label3. Text = R.next (0,Ten).            ToString (); }        }    }

two. Learning from GDI

Learn GDI here, this is what we can easily draw on the form, the following simple implementation of his features are as follows:

Private voidButton1_Click (Objectsender, EventArgs e) {Graphics g= This. CreateGraphics ();//GUI Drawing classPen p =NewPen (Brushes.blue);//call the color brush directly using the brushes method in this class of penG.drawline (P,NewPoint (Ten, -),NewPoint ( -, $));//call a method in the Graphics class DrawLine//to draw out a day line, the parameters in the method are the starting point and the ending pointpoint[] num = {NewPoint (Ten, -),NewPoint ( -, +),NewPoint ( the, -),NewPoint ( -, the)};        G.drawlines (P,num); }

This is the content of today's study, hey, I feel in the study of multi-threaded time or the actual connection with the computer is quite large, and not just to see us in the environment to write programs, and then show in the VS, OK, it is written here, hehe.

Multi-threaded learning and GDI learning

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.