Reputation: 8256
I am busy creating a WCF Web Service, that needs an ASYNC call. I have done this so far:
public async Task<bool> sendData(Data data) {
bool sent = await Task<bool>.Factory.StartNew(() => {
return someNameSpace.ReceiveData(data);
});
return sent;
}
So my question is, does the call to the dll also need to be marked as async?
ie. within the dll
public async Task<bool> ReceiveData(Data data) {
// some async code
// some code here
}
Upvotes: 0
Views: 462
Reputation: 456507
You may find my async
/await
intro helpful. I also have a post specifically dealing with async
WCF.
Some general points:
StartNew
(or Task.Run
) unless you explicitly want to run some code on a background thread.Task
, regardless of where it came from. A method that returns a Task
may or may not be async
- it only makes a difference within that method.So, if your ReceiveData
is either of these (they look the same to SendData
):
public async Task<bool> ReceiveData(Data data);
public Task<bool> ReceiveData(Data data);
Then you can just await
it in SendData
:
public async Task<bool> SendData(Data data)
{
bool sent = await someNameSpace.ReceiveData(data);
... // do other stuff
return sent;
}
Upvotes: 6