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 8072097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:54:31+00:00 2026-06-05T13:54:31+00:00

I have a WPF application in which i have to do a long running

  • 0

I have a WPF application in which i have to do a long running task (basically reading from network). Just to give you a snapshot I am doing the following thing on button click

 Dim t As Task(Of String) = Task.Factory.StartNew(Of String)(Function()
                                                                        'Thread.sleep is simulating long running task that will make UI unresponsive
                                                                        Thread.Sleep(10000)
                                                                        Return "Hello world from async task"
                                                                    End Function)

        TextBlock1.Text = t.Result

I cannot use Event based async methodology because the reading API actually exist in a dll which i refer in my program, that contains a function Public function ReadFromNetwork() as String. This API is making an async call to network to read a long string and return to UI. So, in short i m doing TextBlock1.Text = ExternalDll.ReadFromNetwork().

but the problem is that even if i use Task asynchrony, the UI is still unresponsive.

Can you please detect if i m missing something in code.

Any help/suggestion will be highly appreciated
Thanx in advance

  • 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-05T13:54:32+00:00Added an answer on June 5, 2026 at 1:54 pm

    You’re using t.Result on the line after you start the task. That will make the thread block until the task completes – so all the asynchrony is in vain.

    You should attach a continuation using Task.ContinueWith, and put the code using the task result into that continuation. That will allow the UI to go back to handling events while the task is executing, and then your continuation will be fired when the task has completed. Pass in TaskScheduler.FromCurrentSynchronizationContext to make sure that the continuation fires on the right thread.

    Note that in the next version of VB/C#, all this will be much easier with async methods. If you’re able to use the .NET 4.5 release candidate, you should consider trying this right now – it’ll make your life much simpler.

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

Sidebar

Related Questions

I have a WPF application which has a main window composed from several custom
I have a WPF (C# and .NET 4) application that has a long running
We have a WPF application which gets data from an Analysis Services Cube. The
I have an WPF application which access windows services, task schedulers on the local
I have C# WPF application which reads data from database then does some work.
I have an XBAP WPF application which displays various pages inside of a Frame.
I have a C# WPF application which uses Excel interop libraries to generate and
I have a DataGrid in a WPF application which has for its ItemsSource a
In my WPF application I have a Canvas in which I do some drawing.
I have a C# application of which some parts are written using WPF (which

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.