Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7766893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T15:32:19+00:00 2026-06-01T15:32:19+00:00

I am making some probes with async CTP but I don’t get a good

  • 0

I am making some probes with async CTP but I don’t get a good result, because the GUI is blocked.

I have an WPF application with a button and a textBox for a log. Then I have this code:

private async void btnAsync01_Click(object sender, RoutedEventArgs e)
        {
            UpdateTxtLog("Enter in Button Async01: " + System.DateTime.Now);
            await metodo01Async();
            UpdateTxtLog("Exit button Async01: " + System.DateTime.Now);
        }

private async Task slowMethodAsync()
        {
            UpdateTxtLog("Enter in slowMethod: " + System.DateTime.Now);
            Thread.Sleep(5000);
            UpdateTxtLog("Exit slowMethod: " + System.DateTime.Now);
        }

If am not wrong, set a method with “sync” (click event in this case), it let the method use the await, to return the point to execution to the method which call the actual method, then the execution return to the GUI.

So in the GUI,I click the button, then in the click event await to the slowMethod, how I use await with the slowMethod the control should be returned to the GUI, and then the GUI should not be blocked. However, the GUI is blocked and the txtLog not show any information until slowMethod finish.

Is this because slowMethod is executed in the same thread than the GUI? If I am wrong, with async normally use the same thread than the method which call the await method, but I think that the reason of the async avoid this.

How can I simulate an slowMethod without thread.Sleep? Perhaps this is the problem, because in slowMethod I sleep the thread, and the thread of slowMethod is the same than the GUI.

This makes me think that is always recommended execute in other thread the code of the async methods? If this is correct, which is the sense to use async if also I need to use task for not blocking the main thread?

When to use async and when to use tasks?

For this probes, I am following the examples in this web: http://www.codeproject.com/Articles/127291/C-5-0-vNext-New-Asynchronous-Pattern

In this example, it’s used client.DownloadStringTaskAsync as slowMethod, but in my case, instead of using a WebClient, I use a dummy method, with a sleep to simulate a slowMethod. I think that is the unique difference.

Thanks.
Daimroc.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T15:32:20+00:00Added an answer on June 1, 2026 at 3:32 pm

    Simulate waits using await TaskEx.Delay(5000), which executes an asynchronous sleep/delay.

    You may also want to read up some more on async/await. There are several good Channel9 videos; Stephen Toub, Eric Lippert, and many other Microsoft bloggers have excellent overviews. Jon Skeet’s “eduasync” blog series is also good for really going deep. I’ve written up an async intro on my own blog, as have many others.

    Here’s how async and await really work, in a nutshell:

    • The async keyword only enables the await keyword. That is all. It does not run the method on a background thread.
    • await only acts asynchronously if its “awaiter” is not completed.

    So in your case, btnAsync01_Click and slowMethodAsync both run on the UI thread. slowMethodAsync will run synchronously (executing Thread.Sleep), and then return to btnAsync01_Click, which awaits the already-completed task. Since the task is already completed, btnAsync01_Click just continues executing without yielding to the UI message loop.

    If you replace Thread.Sleep with await TaskEx.Delay, then btnAsync01_Click will start running on the UI thread, and will call slowMethodAsync (also running on the UI thread). When slowMethodAsync awaits the delay (which is not completed), it will return an incomplete task to btnAsync01_Click. btnAsync01_Click will await that task (which is not completed), and will return to the UI loop.

    When the delay expires, it will complete, and slowMethodAsync will resume (on the UI thread). When slowMethodAsync completes, its returned task will complete, and btnAsync01_Click will resume (on the UI thread).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

now i making some problem with JAVA, but don't remember how get lenght between
I'm making some tedious calls to a bunch of functions, but the parameters will
I'm making some tabs and I want to have my own delegate for them
I am making some paging, and I need to make some query and get
I'm making some kind of movie with a webpage. For that I have to
Im making some of my ajax visible for google. To do that, I have
After making some changes to a method, I find it utterly annoying to have
I'm making some frontend experiments and I'd like to have a very basic webserver
I am probably making some silly mistake but I am newer to the world
I am programatically making some LinkButtons, and they worked fine for a while, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.