I'm pretty new in developing UWP apps and using await/async. I try getting a file from local folder of UWP app, but the app is hanging. The file exists on drive.
I wrote some test methods to try identifying the issue, but I don't understand, why it doesn't work. Two runs working fine and the third hangs always.
Has someone an idea, what I'm doing woring?
Code:
public void Test()
{
for (var i = 0; i < 10; i++)
{
KLogger.Log.Debug("");
KLogger.Log.Debug("### Started : " + i);
// create new or returns existent file
var task = TestGetNewFile("test.txt");
//task.ConfigureAwait(false);
task.Wait();
var res = task.Result;
task.Dispose();
KLogger.Log.Debug("### Done : " + i);
}
}
public async Task<IStorageFile> TestGetNewFile(string fileName)
{
var storageFolder = ApplicationData.Current.LocalFolder;
KLogger.Log.Debug("Creation started.");
var fileItem = await storageFolder.TryGetItemAsync(fileName);
KLogger.Log.Debug("Creation finished.");
return null;
}
Log Output:
2018-08-12 00:41:07.282 +02:00 [DBG]
2018-08-12 00:41:07.282 +02:00 [DBG] ### Started : 0
2018-08-12 00:41:07.284 +02:00 [DBG] Creation started.
2018-08-12 00:41:07.289 +02:00 [DBG] Creation finished.
2018-08-12 00:41:07.289 +02:00 [DBG] ### Done : 0
2018-08-12 00:41:07.289 +02:00 [DBG]
2018-08-12 00:41:07.289 +02:00 [DBG] ### Started : 1
2018-08-12 00:41:07.289 +02:00 [DBG] Creation started.
2018-08-12 00:41:07.300 +02:00 [DBG] Creation finished.
2018-08-12 00:41:07.300 +02:00 [DBG] ### Done : 1
2018-08-12 00:41:07.300 +02:00 [DBG]
2018-08-12 00:41:07.300 +02:00 [DBG] ### Started : 2
2018-08-12 00:41:07.300 +02:00 [DBG] Creation started.
-- nothing more in log file --