Ganeshja
Ganeshja

Reputation: 2765

Backgroundworker in C#

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

Upvotes: 2

Views: 229

Answers (3)

Arie
Arie

Reputation: 5373

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

Upvotes: 0

Immortal Blue
Immortal Blue

Reputation: 1700

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.

Upvotes: 0

Rik
Rik

Reputation: 29243

Did you assign the event handlers?

bwgFile.DoWork += bgwFile_DoWork;
bwgFile.RunWorkerCompleted += bgwFile_RunWorkerCompleted;

Are you sure FormFieldsLoad terminates?

Upvotes: 3

Related Questions