none
Some codes in the Form_load event do not run RRS feed

  • Question

  • I have some codes in the form_load event do not run. Similar problem happen in elsewhere. Please help me to take a look:

    public FrmIntelligent()
            {
                InitializeComponent();
            }

            private void FrmIntelligent_Load(object sender, EventArgs e)
            {

                int TotalIntel = 0;
                TotalIntel = CurrentCharacter.Find(x => x.ID == CurrentParty.Leader).Intrigue;
                //if (CurrentCharacter.Any(x => x.Position == "议曹史"))
                if(CurrentParty.Positions[3]!=0)
                {
                    labelAdvisor.Text = "议曹史:" + CurrentCharacter.Find(x => x.ID == CurrentParty.Positions[3]).Name;
                    TotalIntel += CurrentCharacter.Find(x => x.Position == "议曹史").Intrigue;            
                }
                labelIntelligent.Text = "势力谋略:" + TotalIntel;
                labelSpy.Text = "可用间谍:" + CurrentParty.UnocupiedAngency(0) + "/" + CurrentParty.IntelAgency[0];
                labelAssacinate.Text = "可用杀手:" + CurrentParty.UnocupiedAngency(1);
                progressBarTrainAgency.Value = IntelAgencyProgress[1];
                Console.WriteLine(IntelAgencyProgress[1])//This line and below in the event do not run. WHY????
                if (IntelAgencyProgress[1] == -1) { comboBoxAgencyTrain.Enabled = true; }
            }

            private void comboBoxAgencyTrain_SelectionChangeCommitted(object sender, EventArgs e)
            {
                IntelAgencyProgress[0] = comboBoxAgencyTrain.SelectedIndex;
                IntelAgencyProgress[1] = 0;
                progressBarTrainAgency.Value = IntelAgencyProgress[1];
                comboBoxAgencyTrain.Enabled = false;
            }
        }

    The console.write is a part of my debugging. I did not see any thing comes out. The code seems stop at that point.

                
    Tuesday, March 24, 2020 7:12 PM

Answers

  • Hello,

    From the IDE Debug menu select windows -> exception settings. Check "Common Language Runtime Exceptions", fire up the project without breakpoints, see if something throws an exception.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by antidinosaur Tuesday, March 24, 2020 9:11 PM
    Tuesday, March 24, 2020 8:22 PM
    Moderator

All replies

  • Hello,

    From the IDE Debug menu select windows -> exception settings. Check "Common Language Runtime Exceptions", fire up the project without breakpoints, see if something throws an exception.


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    • Marked as answer by antidinosaur Tuesday, March 24, 2020 9:11 PM
    Tuesday, March 24, 2020 8:22 PM
    Moderator
  • Hi antidinosaur,

    You can use it in windows form if you want to output will display like console applicant please do this

    Right click on your project ---> Application ---> Output type : Console Application 


    I think you need to call this

    {
    
    InitializeComponent();
    AllocConsole();
    
    }
    
    [System.Runtime.InteropServices.DllImport("kernel32.dll")]
    private static extern bool AllocConsole();




    Please remember to mark the replies as answers if they helped you :) ~




    • Edited by Rebin Qadir Tuesday, March 24, 2020 9:03 PM
    Tuesday, March 24, 2020 8:37 PM
  • Thank you so much! I am new to C#. I expect the program will stop if there is any error. It turns out that I assigned -1 to a progress bar range from 0 to 100, but the exception did not make the program stop. 
    Tuesday, March 24, 2020 9:15 PM
  • Thank you so much! I am new to C#. I expect the program will stop if there is any error. It turns out that I assigned -1 to a progress bar range from 0 to 100, but the exception did not make the program stop. 

    Your welcome. Now uncheck the checkbox I had you check as keeping it checked will override any and all try-catch statements. In the future don't use form load, instead use form shown.

    The easy way to use form Shown, while viewing code, type in the following and press TAB

    You then get

    Replace the throw new NotImplementedException with the code you would had done in form load.

    In many cases form load swallows exceptions. Using the technique I showed once the problem has been resolved should be unchecked if you happen to use any try-catch statements as having it checked will override all try-catch statements.

    Does this make sense to you?


    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Tuesday, March 24, 2020 11:13 PM
    Moderator