多线程初步了解,源代码贴上

1.没有参数的线程启动

        private void BindUserInfo()
        {
            Thread t = new Thread(new ThreadStart(this.BindUserInfoThreadMethod));
            t.Start();
        }


        private void BindUserInfoThreadMethod()
        {
            Thread.Sleep(1000);
            this.BeginInvoke(new NoArgDelegate(this.BindUserInfoMethod));
        }


        private void BindUserInfoMethod()
        {
        }

2.带参数的线程启动

         private void PersonalDrug(string ID)
        {
            Thread t = new Thread(new ParameterizedThreadStart(this.PersonalDrugThreadMethod));
            t.Start(ID);
        }

        private void PersonalDrugThreadMethod(Object obj)
        {
            Thread.Sleep(5);
            string id = obj as string;
            this.BeginInvoke(new OneArgDelegate(this.PersonalDrugMethod), id);
        }

        private void PersonalDrugMethod(string ID)
        {}

你可能感兴趣的:(C#)