Isabell
asked on
can't use async/await in a method
Hi,
I am trying to make the button in the winForm using async so that the application can be more responsive.
When the button is clicked, it execute the batch files in a List.
But I am getting the following error on await line:
('string' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'string' could be found. (are you missing a 'using' directive or an assembly reference?)
What am I doing wrong?
I am trying to make the button in the winForm using async so that the application can be more responsive.
When the button is clicked, it execute the batch files in a List.
private async void GoBtn_Click(object sender, EventArgs e)
{
...
foreach (var file in batchFiles)
{
...
await Execute(batchfile, resultFolder);
}
// Wait until it's done
WaitUntilTestDone(folder, resultFolders);
.....
}
}
In here. Execute() method returns string.But I am getting the following error on await line:
('string' does not contain a definition for 'GetAwaiter' and no accessible extension method 'GetAwaiter' accepting a first argument of type 'string' could be found. (are you missing a 'using' directive or an assembly reference?)
What am I doing wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks!
You could for example use a ref variable of type string in your Execute method so the declaration is something like
void Execute(ref string str, xxx batchfile, yyy resultfolder)
where xxx and yyy are the types you currently use.