Skip to content

Async Programming (Task)

Muhammad Afzal Qureshi edited this page May 16, 2014 · 3 revisions
  • Introduced with .net Framework 4.0
  • The task class represents the ongoing operation.
  • A generic version of Task acts like a promise which will be available in the future once the operation is completed. The result of this operation will be of type T.
  • Any method which invokes the task should be prefixed by async keyword.
  • All methods that returns tasks must be called by prefixing await keyword.

public Task<bool> DoSomethingTimeConsuming()

    {
        return Task.Run(
            () =>
                {
                    // your rocket science logic
                    return true;
                });
    }

` public async void CallSomethingTimeConsuming()

    {
        var isCompleted = await this.DoSomethingTimeConsuming();
    }`
Clone this wiki locally