If parsing is time consuming, you can run it in a separate thread.
You can raise an event on FileParser when progress changes and subscribe to this event in MainWindow:
private void StartParsing()
{
FileParser fp = new FileParser("FileName.txt");
fp.ProgressChanged += FileParser_ProgressChanged;
Thread t = new Thread(fp.GenerateCmds);
t.Start();
}
private void FileParser_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Dispatcher.BeginInvoke(new Action(
() => { progressbar.Value = e.ProgressPercentage; }));
}
, FileParser:
internal class FileParser:ImageFileParser
{
internal event EventHandler<ProgressChangedEventArgs> ProgressChanged;
ImageFileParser.GenerateCmds()
{
percentage=change;
OnProgressChanged(percentage);
}
internal protected void OnProgressChanged(int percentage)
{
var p = ProgressChanged;
if(p != null)
{
p(this, new ProgressChangedEventArgs(percentage, null));
}
}
}