本文介绍了如何将backgroundWorker用于2个较长的过程取决于选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,先生,我是Uday

在我的C型Winform中,

我有两个长时间运行的方法 uploadUsingText() uploadUsingExcel()


一次选择一个过程取决于组合框的选择.选择后,我必须显示picturebox1可见为true.处理完成后,picturebox1必须可见false.

我的代码是
像这样

 如果(isFiletypeSelect())
            {
                如果(cmbSelectFileType.Text == " 文本" )
                {
                    如果(validation())
                    {
                        panel2.Visible =  true ;
                        
                         pictureBox1.Visible =  true ;
                        uploadUsingText();
                        //  panel1.Enabled = true; 

                        panel2.Visible =  false ;

                    }
                }
                如果(cmbSelectFileType.Text == "  Excel" )
                {
                    如果(validation())
                    {
                        uploadUsingExcel();
                    }

                }

            } 




如何使用backgroundWorker检查方法是否完成取决于选择?
如何根据2种长方法使用backgroundWorker取决于选择?

我已经尝试了以下代码中的上述代码

私有空backgroundWorker1_DoWork(对象发送者,DoWorkEventArgs e){}

请给我解决方法.
首先,您需要声明一个表单级别的BackGroundWorker,并在您的表单构造函数中为其DoWork事件添加一个处理程序.然后,您可以简单地在DoWork事件中运行上述代码,如下所示:

 BackgroundWorker bgw =  BackgroundWorker();

        公共 Form1()
        {
            InitializeComponent();
            bgw.DoWork + =  DoWorkEventHandler(bgw_DoWork);
            button1.Click + =  EventHandler(button1_Click);
        }

        无效 button1_Click(对象发​​件人,EventArgs e)
        {
            bgw.RunWorkerAsync();
        }

        无效 bgw_DoWork(对象发​​送者,DoWorkEventArgs e)
        {
            如果(cmbSelectFileType.Text == " 文本" )
            {
                如果(Validation())
                {
                    panel1.Enabled =  false ;
                    pictureBox1.Visible =  true ;
                    UpLoadUsingText();
                }
            }
            其他 如果(cmbSelectFileType.Text == "  Excel")
            {
                如果(Validation())
                {
                    panel1.Enabled =  false ;
                    pictureBox1.Visible =  true ;
                    UpLoadUsingExcel();
                }
            }
        } 



希望对您有帮助


Hi Sir I am Uday

In my c sharp winform,

I have two Long Running method uploadUsingText() and uploadUsingExcel()


One process is selected at time depends upon combobox selection.after selection i have to show picturebox1 visible true. and after process is finished picturebox1 must visible false.

my code is
Like this

if (isFiletypeSelect())
            {
                if (cmbSelectFileType.Text == "Text")
                {
                    if (validation())
                    {
                        panel2.Visible = true;
                        
                         pictureBox1.Visible = true;
                        uploadUsingText();
                        // panel1.Enabled = true;

                        panel2.Visible = false;

                    }
                }
                if (cmbSelectFileType.Text == "Excel")
                {
                    if (validation())
                    {
                        uploadUsingExcel();
                    }

                }

            }




How to check method is finished using backgroundWorker depends upon selection?
How i can use backgroundWorker for 2 long methods depends upon selection?

I have tried for above code in following

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e){}

please give me solution.
Thanks

解决方案


这篇关于如何将backgroundWorker用于2个较长的过程取决于选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 17:29