I have an old application in Windows Forms, which in many places do some searches on database. Sometimes it takes a lot of time, so I decided to create a loading screen in wpf to show the user that something is loading in separate thread. Basically it's just a full transparent window with loading indicator(a turning circle). Everything works fine on My host computer and on my Virtual Machine, but when I'm trying to deploy it to our demo environments its like - it starts loading the indicator is shown and after few seconds it dissapear and application stops responding like forever. My first thought was that it's the problem with GPU acceleration, that it can't process transparency, but it's being shown for few seconds so it can't be the problem. So most likely I did something bad. Below You can see my code, do You notice something which might be wrong/cause deadlock or something ?
public class LoadingManager { public LoadingManager() { } public LoadingManager(string LoadingText) { loadingText = LoadingText; } private string loadingText = "Please wait .."; private Thread thread; private bool ThreadReadyToAbort = false; private BusyIndicatorView loadingWindow; public void BeginLoading() { this.thread = new Thread(this.RunThread); this.thread.IsBackground = true; this.thread.SetApartmentState(ApartmentState.STA); this.thread.Start(); } public void EndLoading() { if (this.loadingWindow != null) { this.loadingWindow.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => { this.loadingWindow.Close(); })); while (!this.ThreadReadyToAbort) { }; // I also tried to remove this while but it didn't help } this.thread.Abort(); } public void RunThread() { this.loadingWindow = new BusyIndicatorView(); loadingWindow.tbLoadingCaption.Text = loadingText; this.loadingWindow.Closing += new System.ComponentModel.CancelEventHandler(waitingWindow_Closed); this.loadingWindow.ShowDialog(); } void waitingWindow_Closed(object sender, System.ComponentModel.CancelEventArgs e) { Dispatcher.CurrentDispatcher.InvokeShutdown(); this.ThreadReadyToAbort = true; } EDIT.
I noticed that on this machines it usually(sometimes it also fails at first click) works when i click search for the first time. If i click another time it's showing for a second than dissapearing and application stops responding. So it seems like Thread is not beeing shutdown, Dispatcher shutdown failed ? But no exceptions are thrown ...