Reputation: 37633
I have got this code. It works but it freezes the UI. What I want to know is how to use WPF BeginInvok method corectly?
private void ValidateAuthURL_Click(object sender, RoutedEventArgs e)
{
((Button)sender).Dispatcher.BeginInvoke(DispatcherPriority.Input,
new ThreadStart(() =>
{
bool result = false;
try
{
Upvotes: 0
Views: 369
Reputation: 1500504
Your delegate is going to be executed in the UI thread. That's what Dispatcher.BeginInvoke
is there for. I assume you really want to execute that delegate in a background thread... then you should use Dispatcher.BeginInvoke
to get back to the UI thread in order to update the UI later.
In terms of getting to a background thread, you could:
ThreadPool.QueueUserWorkItem
)BackgroundWorker
Task.Factory.StartNew
(if you're using .NET 4)Upvotes: 3