I have a long running process that runs on my UI thread that I cannot move off of the UI thread. Instead I am trying to create a second UI thread that has a waiting animation. Here's the code I'm using to create the second UI thread:
Private _busyThread As Thread
Private _waitWindow As WaitWindow 'This is the window with the animation
Private Sub StartBusyIndicator(ByVal busyInfo As BusyInfo)
_busyThread = New Thread(New ThreadStart(AddressOf ThreadStartingPoint))
_busyThread.SetApartmentState(ApartmentState.STA)
_busyThread.IsBackground = True
_busyThread.Start()
End Sub
Private Function ThreadStartingPoint() As ThreadStart
_waitWindow = New WaitWindow
_waitWindow.Show()
System.Windows.Threading.Dispatcher.Run()
End Function
How can I close this gracefully when needed? I can't access _waitWindow from the main UI thread to close it. If I issue _busyThread.Abort() it doesn't actually close the window.