I am trying develop a Windows App and run into issues. I have a MainPage.xaml and 2 others StartScreen.xaml and Player.xaml. I am switching content of the MainPage if certai
As the exception says, you are not allowed to call Directory.Exists synchronously in the UI thread. Putting the whole code block in a Dispatcher action still calls it in the UI thread.
In a UWP app you would usually use the StorageFolder.TryGetItemAsync method to check if a file or folder exists:
private async void GoToPlayer_Click(object sender, RoutedEventArgs e)
{
var folder = await StorageFolder.GetFolderFromPathAsync(main.workingDir);
if ((folder = await folder.TryGetItemAsync(IDText.Text) as StorageFolder) != null &&
(folder = await folder.TryGetItemAsync("Tracks") as StorageFolder) != null)
{
...
}
}
Note that you may still get an UnauthorizedAccessException when the application is not allowed to access main.workingDir.