Last active
September 2, 2016 19:46
-
-
Save matthewjberger/f0caa019816851c11e05baef73b303fc to your computer and use it in GitHub Desktop.
Executes code from a wpf app on an STA thread synchronously and sets the cursor to busy.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void ExecuteOnSTAThread(ThreadStart t) | |
{ | |
Mouse.OverrideCursor = Cursors.Wait; // Make the mouse cursor a busy spinner | |
Thread thread = new Thread(t); | |
thread.SetApartmentState(ApartmentState.STA); | |
thread.Start(); | |
thread.Join(); | |
Mouse.OverrideCursor = null; | |
} | |
ExecuteOnSTAThread(new ThreadStart(() => | |
{ | |
try | |
{ | |
// TODO: Your code goes here. | |
} | |
catch (Exception ex) | |
{ | |
MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); | |
} | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment