Alex Rivera | Logout

Async modifier in C#

Asked 2013-07-01T14:13:26.233
21

I have the question, what is the difference between these two methods?

    async private void Button_Click_1(object sender, RoutedEventArgs e)
    {
        Thread.Sleep(2000);
    }

    private void Button_Click_2(object sender, RoutedEventArgs e)
    {
        Thread.Sleep(2000);
    }

Both of them block my UI. I know that I must start another thread to avoid blocking, but I have found:

"An async method provides a convenient way to do potentially long-running work without blocking the caller's thread".

I'm a bit confused.

c#
Edit
Report

1 Answer

11

async by itself will not enable asynchronous (non-blocking) method invocation.
You should use await inside the async function.

You should read this to have a better understanding of this capability.

answered 2013-07-01T14:17:01.217

Your Answer