backgroundworkerで非常に長いコードを実行していますが、ネットワーク上の問題が発生し、webexceptionが表示されることがあります。例外ブロック、私はそれをキャンセルした後、同じbackgroundworker上で再び関数を呼び出そうとしましたが、私はそれを正しくやっていないようですエラーが発生した場合にbackgroundworkerで関数を再度呼び出す方法
私のコードを確認してください、それは本当に長いので、それは 十分でない場合には、事前
public static DataSet ds_input;
private void btn_process_Click(object sender, EventArgs e)
{
//some code here to fetch data and call backgroundworker
backgroundWorker1.RunWorkerAsync(ds);
}
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
//ds_input is a dataset with data in it
e.Result = check_number(ds_input);
}
private void backgroundWorker1_ProgressChanged(object sender, System.ComponentModel.ProgressChangedEventArgs e)
{
int i = e.ProgressPercentage;
int j = showProgress(i, Total_Record);
lbl_counter.Text = "Processing " + Convert.ToString(i + 1) + "/" + Convert.ToString(Total_Record) + " ";
}
private void backgroundWorker1_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
DataTable dt = e.Result as DataTable;
Grid_records.DataSource = e.Result;
}
public void check_number(DataSet ds)
{
try
{
// logic here to perform execution
//sometime it break due to internet connectivity
// i want to resume it in catch block
}
catch (System.Net.WebException ex)
{
//how to run backgroundWorker1 here again
// i did this
backgroundWorker1.CancelAsync();
backgroundWorker1.Dispose();
backgroundWorker1.RunWorkerAsync(ds_input);
// but it says -This BackgroundWorker is currently busy and cannot run multiple tasks concurrently.
//how to resume the function on same backgroundWorker1
}
finally
{
}
}
}
廃棄オブジェクトは使用できません。 – wonderbell