は、私がチェックする機能を作成したファイルにデータを追加します。UWP:作成し、確認し、ファイル「test.txtの」が存在する場合
Public Function CheckIfFileExists(sFileName As String) As Integer
Dim Location As Windows.Storage.StorageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation
Dim lstfiles = Location.GetFilesAsync(Search.CommonFileQuery.OrderByName)
Dim foundfiles = lstfiles.GetResults
Dim bFound As Integer
bFound = 0
If foundfiles IsNot Nothing Then
For Each sFile In foundfiles
If sFile.Name = sFileName Then
bFound = 1
Exit For
End If
Next
End If
Return bFound
End Function
を今、私が最初に私の主な機能にCheckIfFileExists(FILENAME)を呼び出すとき、例えば
CheckIfFileExists("test.txt")
、それは私が予期しない時にメソッド呼び出しだと言って、「System.Runtime.InteropServices.COMException」を返します。
Exception thrown: 'System.UnauthorizedAccessException' in mscorlib.ni.dll
私は非同期関数を同期関数で使用しているという事実に関連していますか?
「はい」の場合、機能を非同期に変更するにはどうすればよいですか?
ありがとうございます!
Public Async Function CheckIfFileExists(sFileName As String) As Task(Of Integer)
Dim Location As Windows.Storage.StorageFolder = Windows.ApplicationModel.Package.Current.InstalledLocation
Dim lstfiles = Await Location.GetFilesAsync(Search.CommonFileQuery.OrderByName)
Dim foundfiles = lstfiles
Dim bFound As Integer
bFound = 0
If foundfiles IsNot Nothing Then
For Each sFile In foundfiles
If sFile.Name = sFileName Then
bFound = 1
Exit For
End If
Next
End If
Return bFound
End Function
そしてCheckIfFileExists方法:
を[MCVE]を提供してください。 – IInspectable
要件を満たすために変更された質問 – bluefox
これは[mcve]ではありません。 – IInspectable