How do i keep an animated gif running while my app is running a sub. The whole UI is blocked so I've tried displaying it in another form but i get the same result.
+1
A:
You should have a look at
The BackgroundWorker class allows you to run an operation on a separate, dedicated thread. Time-consuming operations like downloads and database transactions can cause your user interface (UI) to seem as though it has stopped responding while they are running. When you want a responsive UI and you are faced with long delays associated with such operations, the BackgroundWorker class provides a convenient solution.
astander
2010-02-12 12:27:36
so i guess that i should make the sub run into a different thread rather then the animated gif. this is gonna take some re-writing of my app.
Iulian
2010-02-12 12:37:54
Anything done in the doWork of a background worker runs on a worker thread and leaves the UI thread alone. You can use RunCompleted to determine when the process is over, or ReportProgress during. Its quite the handy class.
Kyle Rozendo
2010-02-12 12:42:06
+1
A:
Two things:
- Use a
BackgroundWorker
(example below) - Rather use an indeterminate progress bar if you can, but this depends on technology used.
Example on BG Worker:
Private wrkDeploy As New BackgroundWorker()
Private Sub wndMain_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
AddHandler wrkDeploy.DoWork, AddressOf wrk_DoWork
AddHandler wrkDeploy.RunWorkerCompleted, AddressOf wrk_RunWorkerCompleted
End Sub
Private Sub wrk_RunWorkerCompleted(ByVal sender As Object, ByVal e As RunWorkerCompletedEventArgs)
' Hide Gif and start normal UI process again
End Sub
Private Sub wrk_DoWork(ByVal sender As Object, ByVal e As DoWorkEventArgs)
' Do all heavy work here
End Sub
Private Sub btnFilter_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Show GIF and disable whatever you need to
wrkDeploy.RunWorkerAsync()
End Sub
Kyle Rozendo
2010-02-12 12:34:25