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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:24:57+00:00 2026-05-20T19:24:57+00:00

In a C# winforms program, I have an event that fires when someone attempts

  • 0

In a C# winforms program, I have an event that fires when someone attempts to rename a project. In the EventArgs for that event, I have a “Cancel” property that the event listeners can set to true to (ideally) cancel the rename (if the name is already in use, for example):

ProjectRenamedEventArgs args = new ProjectRenamedEventArgs(oldName, newName);

if (NameChanged != null)
    NameChanged(this, args);

if (args.Cancel)
{
    // Cancel
}
else
{
    // Continue
}

The problem is, the “if (args.Cancel….” line is never reached. I’m guessing that execution is continuing right after the event is fired, and thus args.Cancel is always false so the rename always happens. How would I make execution halt until all of the event listeners have finished their work (giving args.Cancel a chance to be set to true).

I am assuming this is possible because many of the windows forms EventArgs have a Cancel property that allow for whatever just happened to be cancelled (changing the label on a TreeView’s TreeNode, for example).

  • 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-20T19:24:58+00:00Added an answer on May 20, 2026 at 7:24 pm

    You say: “The problem is, the ‘if (args.Cancel….” line is never reached’

    This tells me that your event handler(s) wired to NameChanged are not returning. Another possibility is that one of these handlers is throwing an unhandled exception, and the above code in your example is swallowing the exception.

    -Oisin

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

Sidebar

Related Questions

How can I have a WinForms program do some specific thing whenever a certain
I have a program that when it starts, opens a winform (it is the
In WinForms, I can design a form and have a TabValue to control which
In Winforms you can say if ( DesignMode ) { // Do something that
I have a WinForms .NET app that, according to the Vista Task Manager with
I have a winforms c# app that has an embedded webbrowser control inside it
I have written a WinForms program in C#.Net to click a button programmatically within
I have a test winforms app with ThreadExceptionHandler that displays a message box when
I have some commercial equipment that I can connect to with a .Net library
I have an enterprise system that is used by a handful of WinForms clients

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.