I've a window that shows a 'working' animation when another thread is running. The window shows and I can see the progress bar but the animation is frozen. The code runs on a ViewModel, and the dispatcher is created in the constructor:
_dispatcher = Dispatcher.CurrentDispatcher;
The code to create the animation and run the process is as follows:
Working wrk;
protected void Search()
{
ImplementSearch();
wrk = new Working();
wrk.Owner = (MainWindow)App.Current.MainWindow;
wrk.WindowStartupLocation = WindowStartupLocation.CenterOwner;
wrk.HeadingMessage = "Searching...";
wrk.UpdateMessage = "Running your search";
wrk.ShowDialog();
}
void ImplementSearch()
{
System.Threading.Thread thread = new System.Threading.Thread(
new System.Threading.ThreadStart(
delegate()
{
System.Windows.Threading.DispatcherOperation
dispatcherOp = _dispatcher.BeginInvoke(
System.Windows.Threading.DispatcherPriority.Normal,
new Action(
delegate()
{
ResetSearch();
string ret = _searchlogic.PerformSearch(SearchTerm, ref _matchingobjects, TypeOfFilter());
if (ret != null)
SearchMessage = ret;
if (_matchingobjects.Count > 0)
{
DataRow row;
foreach (SearchLogicMatchingObjects item in _matchingobjects)
{
row = _dt.NewRow();
row["table"] = item.Table;
row["pk"] = item.PK;
_dt.Rows.Add(row);
}
SelectCurrent();
}
}
));
dispatcherOp.Completed += new EventHandler(dispatcherOp_Completed);
}
));
thread.Start();
}
void dispatcherOp_Completed(object sender, EventArgs e)
{
wrk.Close();
}
I can't figure out why the animation stops? Can anyone help? Thanks