Click here to Skip to main content
15,039,149 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to do an async operation in UploadBtnExecute method.I am working this on wpf. But it shows some error.

error are :-
error 1::-'Task UploadBtnExecute(object)' has the wrong return type

error 2::- 'bool' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'bool' could be found (are you missing a using directive or an assembly reference?)

What I have tried:

button click event to trigger a function
UploadBtnClick = new RelayCommands(UploadBtnExecute, UploadBtnCanExecuteUpload);

public  async Task UploadBtnExecute(object param)
  Progress windowShow = new Progress();
            await  UploadFiles();

public bool UploadFiles(List<Item>  selectedFiles)
//do some upload code here

return true;
Updated 23-Jan-21 21:58pm

See the DownloadFileAsync example here: Async and Await[^]

The problem here is that your UploadFiles method is not async and does not return a Task. If you are uploading from a file, you can use one of the asynchronous methods to accomplish that. Something like

public async Task<bool> UploadFiles(List<Item> selectedFiles)
     string filePath = @"c:\temp\Data.txt";
     using var fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read);
     using var streamReader = new StreamReader(fileStream);//uses default encoding UTF8
     string data = await streamReader.ReadToEndAsync();
     //do something
     return data.Contains("spam");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900