invoke the use of multi-threading and begininvoke ??

        // method declaration accepting an int and returns an empty delegate. 
        public  the delegate  void invokeDelegate ();
         // call to delegate,
         // invokeDelegate new new invokeDelegate the FF = (StartMethod); 

        Private  void the button1_Click ( Object SENDER, EventArgs E) 
        { 
            . MessageBox.Show (Thread.CurrentThread.GetHashCode () the ToString () + " The main thread executed first 1 " ); // the first to perform 
            the thread invokeThread = new new the thread ( new new ThreadStart (StartMethod)); // commissioned to create a thread 
            invokeThread.Start (); //Thread Start 


            String A = String .Empty;
             for ( int I = 0 ; I < 10 ; I ++)       // adjust cycles, will be seen more clearly 
            { 
                the Thread.Sleep ( 1000 ); 
                A = A + " loop executes " ; 
            } 
            MessageBox.Show (. Thread.CurrentThread.GetHashCode () the ToString () + " main thread. 1 " + A); 
            
        } 

        Private  void StartMethod () 
        {
            MessageBox.Show (Thread.CurrentThread.GetHashCode () the ToString (). + " Main thread performs a second " ); 
            button1.Invoke ( new new invokeDelegate (the invokeMethod)); // pass a delegate method; this control is performed dependent delegate
             // the Thread.Sleep (3000); 
            MessageBox.Show (. Thread.CurrentThread.GetHashCode () the ToString () + " child threads. 1 " ); 
        } 
        Private  void the invokeMethod () 
        { 
            // the Thread.Sleep (5000); 
            the MessageBox the .Show (Thread.CurrentThread.GetHashCode (). the ToString () + " main thread execution request method 1 _ " );
        }

         ) ;static  void the GetFile ( String S) 
        { 
            the try 
            { 
                the FileInfo Fi = new new the FileInfo (S); 
                Console.WriteLine ( " file path: {0} " , S); 
                Console.WriteLine ( " File Name: {0} " , Fi. Name.ToString ()); 
                Console.WriteLine ( " file type: {0} " , fi.Extension.ToString ()); 
                Console.WriteLine ( " file size: 0} {K " , fi.Length / 1024
                Console.WriteLine ( " File creation time: {0} " , fi.CreationTime.ToString ()); 
                Console.WriteLine ( " last access time: {0} " , fi.LastAccessTime.ToString ()); 
                Console.WriteLine ( " last write time: {0} " , fi.LastWriteTime.ToString ()); 
            } 
            the catch (Exception EX) 
            { 
                Console.WriteLine (ex.Message); 
            } 
        }

 

Guess you like

Origin www.cnblogs.com/enych/p/12582858.html