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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:18:08+00:00 2026-06-12T12:18:08+00:00

This is a duplication of my question in the Windows Store Apps Forum: I

  • 0

This is a duplication of my question in the Windows Store Apps Forum:

I have an awaitable method returning a Task. It gets passed a delegate designated to make a decision. The task iterates though some objects and invokes the delegate to determine if an object should be processed. In classic .NET I would implement that as follows:

private Task ProcessDemo(Func<int, bool> processDecisionHandler)
{
   // Get the current SynchronizationContext
   SynchronizationContext synchronizationContext = SynchronizationContext.Current;

   return Task.Run(() =>
   {
      for (int i = 0; i < 10; i++)
      {
         // Invoke the process decision handler in the UI thread 
         bool process = false;
         synchronizationContext.Send((state) => { process = processDecisionHandler(i); }, i);
         if (process)
         {
            // Process the item
            ...
         }
      }
   });
}

This method could be invoked like this:

private async void testButton_Click(object sender, RoutedEventArgs e)
{
   this.WriteLine("UI-Thread ({0})", Thread.CurrentThread.ManagedThreadId);

   Func<int, bool> handler = (i) =>
   {
      if (MessageBox.Show("Process " + i + "?", this.Title, MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes)
      {
         return true;
      }
      else
      {
         return false;
      }
   };

   await this.ProcessDemo(handler);
}

In Windows Store Apps I face the problem that the Send method of SynchronizationContext is not available. Post would obviously not work for my goal since I have to “await” the handler result.

How could I achieve my goal anyway without a Dispatcher (that I do not have in library code)?

  • 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-12T12:18:09+00:00Added an answer on June 12, 2026 at 12:18 pm

    If it’s always invoked from the UI thread, then you can do something like this:

    private Task ProcessDemo(Func<int, bool> processDecisionHandler)
    {
      for (int i = 0; i < 10; i++)
      {
        // Invoke the process decision handler in the UI thread
        if (processDecisionHandler(i))
        {
          // Process the item on a threadpool thread.
          await Task.Run(...);
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is what is the best practice question. I have 3 tables: orders, customer
Not sure if this is the usual sort of question that gets asked around
Before this question is blocked for duplication, I would like to mention is that
This is my first ever question on SO. So I have a MYSQL table
I apologize if this question is duplication of some other similar question. I am
This is somewhat related to this question . Let's say I have a package
This is a basically duplication of this question . However, I'm looking for the
First I apologize for the duplication, I know this question was asked and I
this is my first question in here, and I would like to ask if
This question is directly related to this SO question I posed about 15 minutes

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.