Exception System.Reflection.TargetInvocationException - Backgroundworker
I'm trying to read files which were opened by the openFileDialog into a
richTextBox (called websiteInput_rtxt) using a
backgroundworker(bgFileOpener).
private void bgFileOpener_DoWork(object sender, DoWorkEventArgs e)
{
try
{
foreach (var file in openFileDialog1.FileNames)
{
using (StreamReader sreader = new StreamReader(file))
{
// while the stream reader didn't reach the end of the
file - read the next line and report it
while (!sreader.EndOfStream)
{
if (bgFileOpener.CancellationPending)
{
e.Cancel = true;
return;
}
bgFileOpener.ReportProgress(0, sreader.ReadLine()
+ "\n");
Thread.Sleep(15);
}
}
}
}
catch (Exception) { }
}
private void bgFileOpener_ProgressChanged(object sender,
ProgressChangedEventArgs e)
{
websiteInput_rtxt.AppendText(e.UserState.ToString());
}
When the form is closed while the bgWorker is still running an exception
is thrown which don't seem to be catched, can someone tell me what is
missing or what could cause the exception?
Exception message is called "System.Reflection.TargetInvocationException"
and the innerException says something about the RichTextBox.
No comments:
Post a Comment