C # Example of a method that opens and calls a window body in a multi-thread thread

Source: Internet
Author: User

First step: How to open a form in a thread

            Sendemailprogress progress=new sendemailprogress (); Add form Close Event progress. Closing + = (s, ev) = = {if (progress.                        Isenabledcloseform) {} else { Ev.                Cancel = true;//close the form}}; Control.checkforillegalcrossthreadcalls = false; In this class we do not check whether a cross-thread call is legal thread thread = new Thread (New Parameterizedthreadstart (Showcommonprogressformdialog                )); Thread.                Start ();                    if (IsFirst) {thread.sleep (5000);                IsFirst = false; } progress.            Writemessage ("", "", "");//private static void Showcommonprogressformdialog (Object message) {try {int num = (int) progress.            ShowDialog ();            } catch (Exception){            }        } 

Step Two: Call methods in the body of the window.

Private delegate void Writemessagehandler (String message, enumcolorints ECI, bool isneedsetsize);        <summary>///Show message///</summary>//<param name= "message" ></param> <param name= "ECI" ></param> private void Writemessage (String message, Enumcolorints Eci,bool is              needsetsize) {Font font = new Font (fontfamily.genericmonospace, +, fontstyle.regular);            True if the control's System.Windows.Forms.Control.Handle is created on a different thread than the calling thread (indicating that you must call the control via the Invoke//method); (Note: Gets a value that indicates whether the caller must call the Invoke method when making a method call to the control, because the call is in a thread other than the thread on which the control is created.)                ) if (invokerequired) {Writemessagehandler handler = Writemessage;            Invoke (Handler, new object[] {message, ECI, isneedsetsize});                } else {int index = RtMessageBox.Text.Length;           Rtmessagebox.appendtext (message);     Rtmessagebox.select (index, message.                Length);                            else {switch (ECI) {case enumcolorints.red:                            Rtmessagebox.selectioncolor = color.red;                        Break                            Case EnumColorInts.Green:RtMessageBox.SelectionColor = Color.green;                        Break Case EnumColorInts.Black:default:RtMessageBox.SelectionColor = color.b                            Lack                    Break                }} rtmessagebox.appendtext ("\ r \ n");                Rtmessagebox.selectionstart = RtMessageBox.Text.Length;            Rtmessagebox.scrolltocaret (); }        }

The above only as a personal learning accumulation ...

C # Example of a method that opens and calls a window body in a multi-thread thread

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.