如何将backgroundWorker用于2个较长的过程取决于选择 [英] How to use backgroundWorker for 2 long processes depends upon selection
问题描述
您好,先生,我是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 == " )
{
如果(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
First of all you need to declare a form level BackGroundWorker, and in your form constructor add a handler for it''s DoWork event. Then you can simply run your above code in the DoWork event, something like this:
BackgroundWorker bgw = new BackgroundWorker(); public Form1() { InitializeComponent(); bgw.DoWork += new DoWorkEventHandler(bgw_DoWork); button1.Click += new EventHandler(button1_Click); } void button1_Click(object sender, EventArgs e) { bgw.RunWorkerAsync(); } void bgw_DoWork(object sender, DoWorkEventArgs e) { if(cmbSelectFileType.Text == "Text") { if (Validation()) { panel1.Enabled = false; pictureBox1.Visible = true; UpLoadUsingText(); } } else if (cmbSelectFileType.Text == "Excel") { if (Validation()) { panel1.Enabled = false; pictureBox1.Visible = true; UpLoadUsingExcel(); } } }
Hope this helps
这篇关于如何将backgroundWorker用于2个较长的过程取决于选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!