I have been using in a WinForms C# application BackgroundWorkers to do any WCF service data calls like below:
private void Worker_DoWork(object sender, DoWorkEventArgs e)
{
switch (_workerType)
{
case "search":
Data.SeekWCF seekWcf = new Data.SeekWCF();
_ds = seekWcf.SearchInvoiceAdmin(new Guid(cboEmployer.Value.ToString()), new Guid(cboGroup.Value.ToString()), txtSearchInvoiceNumber.Text, chkSearchLike.Checked, txtSearchFolio.Text, Convert.ToInt32(txtYear.Value));
seekWcf.Dispose();
break;
case "update":
Data.AccountingWCF accWcf = new Data.AccountingWCF();
_returnVal = accWcf.UpdateInvoiceAdmin(_ds);
accWcf.Dispose();
break;
}
}
In order to call the background worker I do for example:
private void btnSearch_Click(object sender, EventArgs e)
{
if (!_worker.IsBusy)
{
ShowPleaseWait(Translate("Searching data. Please wait..."));
_workerType = "search";
_worker.RunWorkerAsync();
}
}
Now, I would like to start migrating to Task (async / await) C# 5.0, so what I did in this example was:
private async void ProcessSearch()
{
Data.SeekWCF seekWcf = new Data.SeekWCF();
_ds = seekWcf.SearchInvoiceAdmin(new Guid(cboEmployer.Value.ToString()), new Guid(cboGroup.Value.ToString()), txtSearchInvoiceNumber.Text, chkSearchLike.Checked, txtSearchFolio.Text, Convert.ToInt32(txtYear.Value));
seekWcf.Dispose();
}
But here I get a message saying that "this async method lacks 'await' operators and will run synchronously".
Any clue on how is the best practice and the right way to do what I want to accomplish?