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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:11:13+00:00 2026-06-12T15:11:13+00:00

I am trying to hash out the functionality of a cancel button for a

  • 0

I am trying to hash out the functionality of a cancel button for a WPF App. Currently there are 2 functions I am focusing on:

    private void AnalysisClick(object sender, RoutedEventArgs e)
    {
        model.RunAnalysis();
    }
    private void CancelClick(object sender, RoutedEventArgs e)
    {

        model.RunAnalysis().Abort;  //Pseudo-code, needs help!
        MessageBox.Show("The Analysis was cancelled.", "Operation Cancelled", MessageBoxButton.YesNo);
    }

The ‘ AnalysisClick ‘ function is started with a button called Begin. The goal of the ‘ CancelClick ‘ button is to stop the Analysis and to provide a dialog box informing the user that the test was stopped. What is the best way to achieve this?

EDIT
I am currently looking into BackgroundWorker and Microsoft Asynchronous Programming Model per Users’ suggestions.

  • 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-12T15:11:14+00:00Added an answer on June 12, 2026 at 3:11 pm

    I agree with the comments above to your question, but if you want to try something quickly Tasks are a great way to do async operation with ability to cancel those tasks. Something like this should work or at least get you started:

    private CancellationTokenSource _cancelAnalysisTask = new CancellationTokenSource();
        private Task _analysisTask;
    
        private void AnalysisClick(object sender, RoutedEventArgs e)
        {
            _analysisTask = Task.Factory.StartNew(() =>
                {
                    if (_cancelAnalysisTask.IsCancellationRequested)
                            return;
                    model.RunAnalysis();
                });
        }
    
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            if (_analysisTask != null)
            {
                _cancelAnalysisTask.Cancel();
                _analysisTask = null;
                MessageBox.Show("The Analysis was cancelled.", "Operation Cancelled", MessageBoxButton.OK);
            }
        }
    

    This is a quick write-up, what I would recommend is putting async functionality into your ViewModel and expose Commands. UI shouldn’t really know the details of operations. Then Cancelling the Task can be written near/before the meat of the operation within the ViewModel, where it makes more sense to abort the expensive operation/loop/etc.

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

Sidebar

Related Questions

I've been really digging into LINQ, and I'm trying to hash out this lambda
Trying to get a value out of 2d array inside of a hash and
We are trying to roll out authentication into my app and it’s not working
I'm trying to regex-out a hash given in a string from a web-service response.
I'm trying to figure out if MonoTouch correctly calls the underlying hash message when
I'm trying to figure out how to store a hash in my Access Database.
I'm trying to sort out the use of the back button with an AJAX
I'm trying to figure out a way to check if a hash has been
I'm still trying to sort out my hash dereferencing. My current problem is I
I'm trying to create a Hash from local variables (tossing out vars that don't

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.