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

  • Home
  • SEARCH
  • 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 8674799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T19:47:35+00:00 2026-06-12T19:47:35+00:00

In my C#/XAML metro app, there’s a button which kicks off a long-running process.

  • 0

In my C#/XAML metro app, there’s a button which kicks off a long-running process. So, as recommended, I’m using async/await to make sure the UI thread doesn’t get blocked:

private async void Button_Click_1(object sender, RoutedEventArgs e) 
{
     await GetResults();
}

private async Task GetResults()
{ 
     // Do lot of complex stuff that takes a long time
     // (e.g. contact some web services)
  ...
}

Occasionally, the stuff happening within GetResults would require additional user input before it can continue. For simplicity, let’s say the user just has to click a “continue” button.

My question is: how can I suspend the execution of GetResults in such a way that it awaits an event such as the click of another button?

Here’s an ugly way to achieve what I’m looking for: the event handler for the continue” button sets a flag…

private bool _continue = false;
private void buttonContinue_Click(object sender, RoutedEventArgs e)
{
    _continue = true;
}

… and GetResults periodically polls it:

 buttonContinue.Visibility = Visibility.Visible;
 while (!_continue) await Task.Delay(100);  // poll _continue every 100ms
 buttonContinue.Visibility = Visibility.Collapsed;

The polling is clearly terrible (busy waiting / waste of cycles) and I’m looking for something event-based.

Any ideas?

Btw in this simplified example, one solution would be of course to split up GetResults() into two parts, invoke the first part from the start button and the second part from the continue button. In reality, the stuff happening in GetResults is more complex and different types of user input can be required at different points within the execution. So breaking up the logic into multiple methods would be non-trivial.

  • 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-12T19:47:36+00:00Added an answer on June 12, 2026 at 7:47 pm

    You can use an instance of the SemaphoreSlim Class as a signal:

    private SemaphoreSlim signal = new SemaphoreSlim(0, 1);
    
    // set signal in event
    signal.Release();
    
    // wait for signal somewhere else
    await signal.WaitAsync();
    

    Alternatively, you can use an instance of the TaskCompletionSource<T> Class to create a Task<T> that represents the result of the button click:

    private TaskCompletionSource<bool> tcs = new TaskCompletionSource<bool>();
    
    // complete task in event
    tcs.SetResult(true);
    
    // wait for task somewhere else
    await tcs.Task;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a multi-xaml metro app. I want to switch between xaml by button
I am working on a Metro App using C++ and XAML. I want to
I am converting a silverlight XAML/C# app to Metro. For C# code there is
I'm working on a Metro app using XAML & C#. I started this using
I'm trying to re-style the Slider control using XAML for a Metro style app
Apologize if I'm wrong, I'm developing metro app using C# and XAML, As we
I'm developing metro app for windows 8 tablet using XAML and C#, so is
I'm developing metro app using C# and XAML, I'm stuck with grid view that
Third party libs to Convert HTML/XAML for Windows 8 Metro App ? I using
I'm developing my first Metro app using XAML. The app is for our company

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.