我有一个长时间运行的进程在我的 UI 线程上运行,我无法离开 UI 线程。相反,我正在尝试创建第二个具有等待动画的 UI 线程。这是我用来创建第二个 UI 线程的代码:
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
我怎样才能在需要时优雅地关闭它?我无法_waitWindow
从主 UI 线程访问以关闭它。如果我发出_busyThread.Abort()
它实际上并没有关闭窗口。