I hate that my first question seems to have been answered many times, but it's still not easy for me when I remember how to call a method using BackgroundWorker.
I am processing a very large text file using a series of classes and methods. The whole process starts after the user selects a tool element. After that, it will look like this:
- User selects toolbar item
- The user selects the file to be processed through the dialog box.
- Action begins
I think I can wrap everything in BackgroundWorker from the moment the user pulled out the initial dialog box, but now I want to make a way where all the heavy lifting is done in his own copy of BackGroundWorker, I will also add a ProgressBar, but I think I can handle this if I can just start the BackgroundWorker process.
From the top (pseudocode used for example, omitted for brevity):
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
string fileName = openSingleFile.FileName;
processFile(fileName);
}
static public void processFile(string fileName)
{
foreach (data in bigData)
{
processItem(stringA, stringB);
x++;
}
}
I created an instance of BackgroundWorker ...:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
}
... and I tried too many things to list, so I went back to the beginning for the presentation above.
If I understand BackgroundWorker, I will need to do the following:
Replace processItem (stringA, stringB) in the above code with something like:
backgroundWorker1.RunWorkerAsync(processItem(stringA, stringB));
... and then make some kind of DoWork call? ... and then make any RunWorkerCompleted call?
, , , . . StackOverflow DOA.
FYI: SO, MSDN DotNetPerls. - , .