问题
Actually, i need to prompt a loading image throwugh backgrounderworker, whenever a particular function is been invoked here is my code :
private void bgwFile_DoWork(object sender, DoWorkEventArgs e)
{
FormFieldsLoad();
}
private void bgwFile_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Cancelled == true)
{
Status.Text = "cancelled";
}
else if (e.Error != null)
{
}
picprocess.SendToBack();
Status.Text = "Completed";
}
//Below Method where i have called RunWorkerAsync()
private void buttonUpload_Click(object sender, EventArgs e)
{
LoadFile(pdfFullPath, txtPassword.Text);
form = document.getDocumentCatalog().getAcroForm();
java.util.List FieldTypes = form.getFields();
availableFieldsTable.Clear();
btnLoad.Enabled = false;
Status.Text = "Document loaded successfully!!!";
picprocess.BringToFront();
bgwFile.RunWorkerAsync();
}
while running the above code , it invokes the loading image but no output is being displayed it keeps on displaying the loading image .. it is not calling up the RunWorkerCompleted
Can any one help me out pls
Thanks
回答1:
Did you assign the event handlers?
bwgFile.DoWork += bgwFile_DoWork;
bwgFile.RunWorkerCompleted += bgwFile_RunWorkerCompleted;
Are you sure FormFieldsLoad
terminates?
回答2:
As @Rik said, have you assigned the event handler?
If you have, put a break point or other trace to verify that your bgwFile_DoWork
method execute as you expect and aren't getting stuck in an infinite loop or something.
回答3:
Does DoWork actually finishes? Will this code print anything in the output window?
private void bgwFile_DoWork(object sender, DoWorkEventArgs e)
{
FormFieldsLoad();
Console.WriteLine("Work done");
} // <-or put a breakpoint here
来源:https://stackoverflow.com/questions/15703045/backgroundworker-in-c-sharp