I referenced Microsoft Learn and wrote a piece of C# code to make the program display a path selector, but VS showed an error message: await can only be used for asynchronous methods, refer to the use of async mark..., but this method is awaitable and has async mark. After trying to compile, there was an error message: "CompileXaml" task returned false, but no error was recorded.
After I changed it to ".AsTask().Result", the program can display the path picker, but the program freezes after it is displayed. Neither the main interface nor the path picker responds (but not the unresponsive state), please ask How to solve the problem?
c#
var folderPicker = new Windows.Storage.Pickers.FolderPicker
{
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop
};
Windows.Storage.StorageFolder folder = await folderPicker.PickSingleFolderAsync(); ->ERROR
if (folder != null)
{
pass
}
else
{
pass
}
c#
var folderPicker = new Windows.Storage.Pickers.FolderPicker
{
SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.Desktop
};
Windows.Storage.StorageFolder folder = folderPicker.PickSingleFolderAsync().AsTask().Result;
if (folder != null)
{
pass
}
else
{
pass
}