Archived Forum Post

Index of archived forum posts

Question:

Why Does Chilkat Implement Async with Task when async/await Already Exists?

Sep 02 '16 at 10:07

When using asynchronous methods - you have created your own implementation of Task that cannot be awaited. While I looked at your example, it still is somewhat confusing to me. For example: what if I wanted to simply do

byte[] request = await clientSocket.ReadBytesAsync();
right now I am doing:
byte[] request = null;
await Task.Run(() =>
{
  request = clientSocket.ReadBytes();
}
which works fine, but is rather wasteful since you have the entire framework in there already. Can you please point me to the right docs?


Answer

The reason Chilkat offers the Async alternatives for methods is to provide a consistent means for asynchronous functionality that is cross-platform and cross-language. Some environments may already provide async capability, and in that case you can freely choose one or the other. For example, using C# in VS2015 provides the the async/await C# language features. However, a programmer using VS2005 (.NET Framework 2.0) does not have async/await.

One difference is w/ the WinRT Chilkat API. In this case, the Chilkat methods are "awaitable" and there is no Chilkat.Task object. For example:

(awaitable) public IAsyncOperation<bool> GetFileAsync(string remoteFilePath, string localFilePath);