Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit 3e5cc2b

Browse files
authored
UWP Dispatcher should use the internal core dispatcher for state (#15716)
* UWP Dispatcher should use the internal core dispatcher for state * And the case where the renderer is not loaded
1 parent 1247c3a commit 3e5cc2b

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2482.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ protected override void Init()
8080
var threadpoolButton = new Button { Text = "Update Instructions from Thread Pool" };
8181
layout.Children.Add(threadpoolButton);
8282

83-
this.Dispatcher.BeginInvokeOnMainThread(() => { instructions.Text = "updated from thread pool 1"; });
83+
this.Dispatcher.BeginInvokeOnMainThread(() => { instructions.Text = "updated from thread pool 1 IsInvokeRequired=" + this.Dispatcher.IsInvokeRequired; });
8484

8585
threadpoolButton.Clicked += (o, a) =>
8686
{
8787
Task.Run(() =>
8888
{
89-
this.Dispatcher.BeginInvokeOnMainThread(() => { instructions.Text = "updated from thread pool 2"; });
89+
this.Dispatcher.BeginInvokeOnMainThread(() => { instructions.Text = "updated from thread pool 2 IsInvokeRequired=" + this.Dispatcher.IsInvokeRequired; });
9090
});
9191
};
9292

Xamarin.Forms.Platform.UAP/Dispatcher.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ public Dispatcher(CoreDispatcher coreDispatcher)
2525
_coreDispatcher = coreDispatcher;
2626
}
2727

28-
bool IDispatcher.IsInvokeRequired => Device.IsInvokeRequired;
28+
bool IDispatcher.IsInvokeRequired => !_coreDispatcher.HasThreadAccess;
2929
}
3030
}

Xamarin.Forms.Platform.UAP/DispatcherProvider.cs

+5
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ public IDispatcher GetDispatcher(object context)
2727
s_current = new Dispatcher(renderer.ContainerElement.Dispatcher);
2828
return s_current;
2929
}
30+
else
31+
{
32+
s_current = new Dispatcher();
33+
return s_current;
34+
}
3035
}
3136

3237
return null;

0 commit comments

Comments
 (0)