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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:51:55+00:00 2026-06-17T20:51:55+00:00

I am building an ASP.NET application using WPF with a long-running asynchronous Task that,

  • 0

I am building an ASP.NET application using WPF with a long-running asynchronous Task that, in some cases, needs to ask the user for some more info. Is there a way I could interrupt, but not cancel, the task, wait for the user to respond and continue based on the result?

All I have found are ways to use callbacks before and after the task. I have tried invoking UI thread methods via Send() of a SynchronizationContext passed from the main thread, but it (sometimes) throws Null Reference Exception.

To be more specific, I am unable to understand why this code throws NullReferenceException when it calls Send():

protected void Page_Load(object sender, EventArgs e)
{
    Task task = new Task(DoSomeWork, new Tuple<SynchronizationContext, object>(SynchronizationContext.Current, new object()));
    task.Start();
}

public void DoSomeWork(object state)
{
    Tuple<SynchronizationContext, object> cst = (Tuple<SynchronizationContext, object>)state;
    cst.Item1.Send(Writer, "Message");
}

public void Writer(object s)
{
    Label1.Text = (s as string);
}
  • 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-17T20:51:56+00:00Added an answer on June 17, 2026 at 8:51 pm

    Take a look at the Async and Await stuff that’s now available in the runtime.

    There’s a bit too much for me to create a sensible demo here, but I can point you at:

    http://msdn.microsoft.com/en-gb/library/vstudio/hh191443.aspx

    which should get you started.

    Update

    Here are a few more links that might help.

    http://code.jonwagner.com/2012/09/06/best-practices-for-c-asyncawait/

    http://www.itwriting.com/blog/4913-a-simple-example-of-async-and-await-in-c-5.html

    http://weblogs.asp.net/dixin/archive/2012/11/02/understanding-c-async-await-1-compilation.aspx

    Note: there is a lot of stuff around on the newer C#5 Async stuff, but if you look hard enough there is still a lot of the C#4 async stuff around too, it’s just that C#5 is in the limelight at the moment, so you might have to sift through things just that little bit further.

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

Sidebar

Related Questions

I am building a web application using ASP.NET MVC that has two very distinct
I'm building an ASP.NET web application using NHibernate and a legacy database. In that
I'm building an ASP.NET application. I'm using a ListView to show some Entities however
We're building a business application using Microsoft ASP.NET MVC 3. Some views are now
I am building an ASP.NET MVC web application and I'm using jQuery for some
I am building a Web Application using asp.net (C#). I come from windows forms
I am building a AJAX intensive web application (using ASP.NET, JQuery, and WCF web
In have my application configured in asp.net. I am using ajaxcontroltoolkit. After building the
I am building an ASP.NET web application that will be deployed to a 4-node
I've been building my sample asp.net application using VWD2008 and the development virtual server

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.