[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Crashing happens when I set a form's public value before close the form.

Posted on 2007-07-20
5
Medium Priority
?
181 Views
Last Modified: 2010-04-15
Hi, I'm using vs2005, .net 2, for windows application.  Below is part of my code where I'm getting crash is when I try to:   showPgMessage = true;
In debug this jumps to the "set" part of code in the declaration "public bool showPgMessage ".  It then repeatedly highlite the "showPgMessage = value; " several times and then it exits the program.  
This form is launched as a dialog from the main form.  At the end of this form when it's closing, I need to set the showPgMessage  value so the main form can retrieve that value.  Why is it not working though?  Thanks.

  public partial class PgMessageBox : Form
    {
        public bool showPgMessage //For scrolling between forms to indicate which info. to disply
        {
            get
            {
                return showPgMessage;
            }
            set
            {
                showPgMessage = value;

            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                if (ckbShowPgMessage.Checked)
                    showPgMessage = false;
                else
                    showPgMessage = true;
                this.Close();
            }                
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message, "PowerADvantage");
            }
        }
    }
0
Comment
Question by:lapucca
  • 3
  • 2
5 Comments
 

Author Comment

by:lapucca
ID: 19533168
Here is the code for calling this dialog form
                    if (!userSupressPgMsg)
                    {
                        userName = drSource["Display Name"].ToString();
                        msg = "Error importing " + userName +
                        ": Primary group GID can not be null.  Please correct and try again.";
                        PgMessageBox pgMsgBox = new PgMessageBox(msg);
                        pgMsgBox.ShowDialog();
                        userSupressPgMsg = pgMsgBox.showPgMessage;
                    }
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 19533183
The name of the property and the field are exactly the same, so you get a recursive call, which causes a StackOverflowException.

You would need something like this:

public bool showPgMessage //For scrolling between forms to indicate which info. to disply
        {
            get
            {
                return _showPgMessage;
            }
            set
            {
                _showPgMessage = value;
            }
        }

Bob
0
 

Author Comment

by:lapucca
ID: 19533729
I'm getting the following error message when I made the change.  Also, do I keep the "showPgMessage = true;" unchanged too?  Thanks.

Error      7      The name '_showPgMessage' does not exist in the current context

        public bool showPgMessage //For scrolling between forms to indicate which info. to disply
        {
            get
            {
                return _showPgMessage;
            }
            set
            {
                _showPgMessage = value;

            }
        }
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 19533797
Oh, yeah, and you have to change the name, or add a field:

  private bool _showPgMessage;

Bob
0
 

Author Comment

by:lapucca
ID: 19534838
Thank you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question