用线程打开时窗体消失 [英] Form when open with thread get disappeared

查看:56
本文介绍了用线程打开时窗体消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我使用线程显示winform时,该窗体就会被打开并迅速消失.不知道为什么有人可以帮助我..

Whenever i use a thread to display a winform than the form get opened and get disappeared quickly. dont know why can any one help me..

public void start_files(object path)
        {
           update frm=new update();
           frm = new update();
           
            frm.Show();

        }

      private void button2_Click_1(object sender, EventArgs e)
        {
                System.Threading.Thread thread_ftp;
                thread_ftp = new Thread(new ThreadStart(start_files));
                thread_ftp.Name = "thread_ftp_start";
                CheckForIllegalCrossThreadCalls = false;
                thread_ftp.Start();

         }

推荐答案

您使用的是对象类型参数,但无法启动此类线程,需要使用

System.Threading.ParameterizedThreadStart =新的System.Threading.ParameterizedThreadStart(对象参数)

否则将对象视为全局变量
There u r using a object type parameter but u can''t start the thread like this u need to use

System.Threading.ParameterizedThreadStart th=new System.Threading.ParameterizedThreadStart(u r object parameter)

or else consider the object as a global variable


为什么?因为创建表单的主题是表单的应用程序":结束时,所有资源都被关闭和处置,就像在常规应用程序中用于常规表单一样.

尝试改用frm.ShowDialog().
Why? Because the thead that creates the form is the "application" for the form: when it ends, all it''s resources are closed and disposed, just as they would be for a regular form in a normal application.

Try using frm.ShowDialog() instead.


这篇关于用线程打开时窗体消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆