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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:19:31+00:00 2026-05-13T18:19:31+00:00

I am programming in C#.NET. It is possible to abort the set procedure of

  • 0

I am programming in C#.NET. It is possible to abort the set procedure of a class property without throwing an exception?

Here is what I want to do…

public int RandomProperty
{
    set
    {
     DialogResult answer = new DialogResult();
     answer = MessageBox.Show("This process could take up to 5 min. Are you sure you want to continue?");
     if(answer = DialogResult.No) 
        CancelSet   // Can I do something similar here?
     else
     {
      ...Do set procedure
     }
    }
}

I don’t think I can use a method (instead of a property) because I am setting this value with a propertygrid.

  • 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-05-13T18:19:31+00:00Added an answer on May 13, 2026 at 6:19 pm

    Under no circumstances should you do any of this. A property should always be fast and logically represent a property of something. Ideally it should never fail. It certainly should not produce side effects such as popping up UI. You’re violating all of these important guidelines. Don’t do it.

    Furthermore, your UI design is bad. Don’t ask a user beforehand “this might take a while, are you sure?” and then punish them with a long wait if they click yes. Instead, start the operation, and if it doesn’t return quickly, pop up a UI element that shows a progress bar and an estimated time left that has a cancel button.

    You should probably write your long-running operation as an asynchronous method that can be cleanly cancelled on another thread.

    A good architecture for this sort of thing is to have your method return immediately an object that exposes events like “I’m still running and here’s how far along I am”, or “I’m done now and here’s the result”, or “I got an error while attempting to do the operation and here’s what it is”. That object can also expose a “cancel” method that knows how to communicate with the worker thread and shut it down cleanly. The caller of the method that gets this object can then decide how to display the UI to the user.

    With this architecture you separate your UI logic, your asynchrony logic and your business process logic from each other cleanly. This is work, but it pays dividends later.

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

Sidebar

Related Questions

I am learning on my own about writing an interpreter for a programming language,

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.