Link to home
Start Free TrialLog in
Avatar of Isabell
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.

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);
                .....
            }
        }

Open in new window

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
Avatar of ste5an
ste5an
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Building on the comment by Ste5an.
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.
Avatar of Isabell
Isabell

ASKER

Thanks!