C# 之前在提问区请教的一个问题,自己变化时发现行不通,遂请问各位老师

  
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //线程清理
            t.Abort();
            if (t1 != null) t1.Abort();
        }
        System.Threading.Thread t = null, t1 = null;
        private void Form1_Load(object sender, EventArgs e)
        {
            this.t=new System.Threading.Thread(() =>
            {
                while (true)
                {
                    var num = System.Diagnostics.Process.GetProcesses().Where(i => i.ProcessName == "notepad").Count();
                    if (num > 0)
                    {//程序被开启,启动新线,3s后执行
                        t1 = new System.Threading.Thread(() => {
                            System.Threading.Thread.Sleep(3000);//先停3s,在执行操作
                            
                            //其他操作
                            MessageBox.Show("记事本程序已启动!");
                            //Form1 frm=new Form1();
                            //frm.Show();
                            t.Abort();
                        });
                        t1.Start();
                    }
                    else if (t1 != null) { t1.Abort(); t1 = null; }
                    System.Threading.Thread.Sleep(3000);//3s检查一次
                }
            });
            this.t.Start(); 
        }

请问在这段代码中,执行其他操作的语句里,用何种语句可以在执行完“MessageBox.Show("记事本程序未启动!");Form1 frm=new Form1();frm.Show();”之后,使循环停止并隐藏这个窗口。学习C#时间不太长,使用break等都没起作用或不能在线程中执行,请问各位老师知道如何能实现这个操作的代码吗,希望有老师指教,谢谢老师

原问题:https://ask.csdn.net/questions/7428950  感谢GoCityPass新加坡曼谷通票老师的回答

 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            //线程清理
            if (t.IsAlive) t.Abort();
            if (t1 != null && t1.IsAlive) t1.Abort();
        }
        System.Threading.Thread t = null, t1 = null;
        delegate void showForm();
        private void Form1_Load(object sender, EventArgs e)
        {
            this.t = new System.Threading.Thread(() =>
            {
                while (true)
                {
                    var num = System.Diagnostics.Process.GetProcesses().Where(i => i.ProcessName == "notepad").Count();
                    if (num == 0 && (t1 == null || !t1.IsAlive))
                    {//未启动对应程序,并且t1未初始化或者未运行状态
                        Console.WriteLine(t1 == null);

                        t1 = new System.Threading.Thread(() =>
                        {
                            System.Threading.Thread.Sleep(3000);//先停3s,在执行操作
                            t.Abort();//要放到MessageBox.Show前面,后面好像无法停止线程。。
                            MessageBox.Show("记事本程序未启动!");
                            if (this.InvokeRequired)//要在线程中打开其他窗体,需要Invoke过,更新窗体控件也需要Invoke
                                this.Invoke(new showForm(() =>
                            {
                                var frm = new Form2();
                                frm.Show();
                            }));

                        });
                        t1.Start();
                    }
                    else if (t1 != null && t1.IsAlive) { t1.Abort(); t1 = null; }

                    System.Threading.Thread.Sleep(3000);//3s检查一次
                }
            });
            this.t.Start();
        }