Hello glowblujel,
I think you can create an anonymous task for this issue like following code.
public MainPage() { this.InitializeComponent(); GetLocalIp().ConfigureAwait(false); } private async Task GetLocalIp() { int timeout = 1000; var task = Task.Run( async () => { try { var icp = NetworkInformation.GetInternetConnectionProfile(); if (icp?.NetworkAdapter != null) { var hostname = NetworkInformation.GetHostNames().SingleOrDefault(hn => hn.IPInformation?.NetworkAdapter != null && hn.IPInformation.NetworkAdapter.NetworkAdapterId == icp.NetworkAdapter.NetworkAdapterId); await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { IPAdressTextBlock.Text = hostname?.CanonicalName; }); } } catch { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () => { IPAdressTextBlock.Text = "Network not found."; }); } }); await Task.WhenAny(task, Task.Delay(timeout)); }
You can also refer to this topic. Hope that is helpful for you.
In addition, please note that, Code running on a background thread/Task cannot manipulate UI elements directly without raising a cross-thread exception. Instead, you must run UI code using a dispatcher. This task snippet encapsulates the typical dispatcher usage in Universal Windows Platform (UWP) apps.
Best Regards,
Michael
MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.