none
On checking a checkbox my app shuts down without exceptions or errors. Was working fine. Cant identify cause RRS feed

  • Question

  • Hello community,

    Thankyou for reading,

    OK, so this is a weird one. Hoping someone has some insight, or can point me in the right direction...

    I have 4 checkboxes setup on a form which I had setup and working how I wanted them.
    Two were used to add and remove tab pages to and from a tabcontrol to a temporary tabpage collection; as checkbox is checked the tabpage is inserted from the collection to the control, unchecked it is reversed (removed from control and added to temporary collection.
    The other two have no code attached to them, their checkstate is applied as a true or false database field by a separate routine.

    As I said, all checkboxes were working perfectly and performed the above tasks many times without issue. For most part I was finished with them.

    I moved on and continued coding for a bit on other things not relating to the checkboxes, however I did rename one via the properties window at some stage.

    So soon I started a debug session, only to find now when I check 3 of the 4 checkboxes the app unexpectedly shuts down. No Break Or Exceptions either. I tried inserting an automatic break into a few test click, check-changed, checkstate handlers for the checkboxes so I could step out my code to pick up an error and find the issue. But the app still just shut down before the break insert seemed to get a chance to implement.
    Only handlers I can get to activate in any way for the checkboxes now are on mouse enter and mouse hover events. Any other way I interact with them the app shuts down again.

    As a test I added other new checkboxes to the same form, and they seem to work fine with event handlers and checkstates working fine. So, with that in mind, its most likely I could easily replace them which would probably fix this.

    But I really need to know the issue, (or would like to at the very least) and any impact it will have on other controls and the rest of the project solution.

    In addition I Have tried cleaning and rebuilding, even rebooting. I Also ran the debug executable on another system and issues persisted.

    No errors or warnings show anywhere, nor can I see any obvious issues with the code. Certainly nothing that was not working 6 or so hours before.

    Im not really sure where to go with this one, was hoping someone may have some insight, please? An Idea Where to look maybe? Or if possible what to check to ensure the checkboxes are, and were defined correctly by the designer. WHich files to check, where to look and such, if possible.

    Perhaps some of the auto code for the designer may have messed something up a bit, perhaps.

    I have invested many hours into this code, if possible I would really like to identify the cause to insure my app will remain stable as I progress

    Thank you for your time, all reply's and help will be greatly appreciated.

    {0_0}

    Monday, May 22, 2017 2:02 PM

Answers

  • Rob,

    .GotFocus is low level and MSDN documentation show that we're not to use it. I don't know that's it but use .Enter and .Leave, not .GotFocus and .LostFocus.

    *****

    Here it is:

    https://msdn.microsoft.com/en-us/library/system.windows.forms.control.gotfocus(v=vs.110).aspx

    The note shows:

    "The GotFocusand LostFocusevents are low-level focus events that are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the GotFocusand LostFocusevents are only used when updating UICuesor when writing custom controls. Instead the Enterand Leaveevents should be used for all controls except the Formclass, which uses the Activatedand Deactivateevents. For more information about the GotFocusand LostFocusevents, see the WM_SETFOCUSandWM_KILLFOCUStopics."

    Also, right beneath that, look at the caution message please.


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Tuesday, May 23, 2017 4:13 AM
  • Well Ive just made a total fool of myself... Just finally found it. Was a typo of all things. Too ashamed to really want to say what it was.

    Cant believe I missed this and that It took so long to realize it.

    The typo is clearly visible at the 'end' of every .gotfocus handler... except the one that works ofc.

    So very, very, very sorry to waist your time.

    Feeling like a fool right now. Although I have swapped the got focus handlers to enter, ty Frank.
    Sorry to waist everyone's time that replied, it was not intentional.

    Will go offline now for a bit I think.. avoid what ridicule I can, lol.

    • Marked as answer by AussieHack Tuesday, May 23, 2017 5:59 AM
    • Edited by AussieHack Tuesday, May 23, 2017 6:08 AM
    Tuesday, May 23, 2017 5:59 AM

All replies

  • AH,

    Is your program 64-bit and is the logic that's used in the form's .Load event handler?

    There's a known issue with that and not throwing an exception sounds like it.

    If you put a breakpoint in, it won't break when you run it? That's very suspect.


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Monday, May 22, 2017 2:07 PM
  • Hi

    Faced with such a situation, my first approach would be to place a break point in the code at an early stage of the code and re-run. If it reaches the breakpoint, then delete that breakpoint and put another at a later stage - keep doing until it just doesn't reach it - then you know where to look.

    '

    If the sudden shutdown is happening without any exception showing up, I wonder if you have any Try....Catch blocks with the Catch having nothing in it - if you are using these blocks, at the very least, put a Stop in the Catch part.


    Regards Les, Livingston, Scotland

    Monday, May 22, 2017 2:11 PM
  • I know this kind behaviour, it happens for instance if there are more events used and for instance a checkbox is changed from inside another event. 

    Than there is direct a checkbox change (or other) called. 

    A simple solution is using Add Handlers and remove the handler you're in which sets up another event. 


    Les suggested to set a breakpoint, the trouble with that is as what happens look what I wrote, that while stepping through your code it goes in many directions and you don't even see why it suddenly goes so many times until something is completely wind up.

    In the case the problem can be like I wrote, then maybe this page can help you to see the order of the events.

    https://msdn.microsoft.com/en-us/library/86faxx0d(v=vs.110).aspx


    Success
    Cor

    Monday, May 22, 2017 2:20 PM
  • If there were something wrong with the way the checkboxes in the hidden code pages of the form then the program would most likely fail to compile.  The fact that it does compile and run, and the error does not occur until you click on a checkbox, indicates that the problem more likely lies somewhere in the runtime code.

    What version of Visual Studio are you using?  Also, have you checked the Windows Event Viewer for any application events related to your program's crash?


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Monday, May 22, 2017 7:22 PM
    Moderator
  • ty for replying Frank,

    Yes app is 64 bit. I do call a checkstate handler for the check box in the form load (using code CheckBox_Checkstatechanged(sender,e)). I do this to initially hide the tab pages related to two of the checkboxes as the form in question displays,
    I tried removing (remarked out) all event handler routines for the checkboxes but still as i click  a checkbox the app still shuts down. Well one still works OK, which just adds to the confusion in my mind.

    I added a break in the form load handler to step code out. Everything works fine till I click a checkbox and the shutdown repeats. My code was stable and still 'seems' fine now. Is a strange one???



    EDIT:
    Seems I missed a couple handlers for my help messages - please see my last post
    • Edited by AussieHack Tuesday, May 23, 2017 2:54 AM
    Tuesday, May 23, 2017 12:27 AM
  • Thankyou for replying Cor,

    Is greatly appreciated.
    As I replied above to frank, I have stepped the code out every which way I can. Everything seems fine and correct (well no errors or such) until i attempt to check a checkbox.


    I have try catches used extensively throughout the code, buy none are attached to checkbock check, click, or such events. Also all try catches have a message box to display the exception it caught while debugging


    • Edited by AussieHack Tuesday, May 23, 2017 2:50 AM
    Tuesday, May 23, 2017 12:33 AM
  • Thankyou for reply Les,

    There are CheckstateChanged and mouse hover handlers attached to the checkboxes in question, mostly have mose event handlers attached. For two their checkstate is used to set a true false database field as the form closes, no handlers were really necessary for this action.

    Checkstate changed handler calls a class routine that removes and inserts tab pages form a tab contol to a temporary collection. Was working great without issue. The mouse hover event is used to trigger a help message as the pointer moves over the checkbox control. Again was working fine. Infact That Part still is working, as I said above, only events I can use on them now seem to be mouse hover and mouse enter


    EDIT:
    Was related to my handlers and how they were setup (tyvm) - please see my last post


    • Edited by AussieHack Tuesday, May 23, 2017 2:58 AM
    Tuesday, May 23, 2017 12:39 AM
  • Thankyou for replying Reed,

    I am using VisualStudio Community 2015, As far as I know I am up to date with updates.

    App still crashes on other systems, and as I say It went form working fine to this unexpected error. Wasnt even coding the checkboxes when it occurred.

    I am the first to admit I clearly dont really totally know what Im doing. But I am learning, and I do Understand The code that I use of course. Just doesn't seem to be a reason in there to explain this.

    Actually, I was typing simple Label.text="Whatever" type code for a help message system on another control (but same form) when the checkboxes messed up.


    • Edited by AussieHack Tuesday, May 23, 2017 2:50 AM
    Tuesday, May 23, 2017 12:47 AM
  • I do have a commit I can revert to just before I added the last chunk of code (will loose about six hours but could be hell of alot worse)
    I am confident I can Re-code and hopefully fix the issue. Also As I said above, new Checkboxes I add to the form  after the fact seem to work fine. Replacing the checkboxes with new ones should fix this also, hopefully.

    But I really should try to ascertain the cause so I don't repeat it; understand my mistake, if at all possible.
    Tuesday, May 23, 2017 1:01 AM
  • Ok I have found the handlers that are causing the issue....

        '
        'Suspend TA's Checkbox
        Private Sub SuspendTakeAways_DisplayQuickHelpTextOnMouseMovment(sender As Object, e As EventArgs) Handles SuspendTakeAwaysCHECKBOX.MouseHover, SuspendTakeaAwaysBorderLABEL.MouseHover, SuspendTakeaAwaysBorderLABEL.MouseEnter
            QuickHelpHandler("SuspendTakeAwaysCHECKBOX") : End Sub
        Private Sub SuspendTakeAways_DisplayQuickHelpTextOnOnControlFocus(sender As Object, e As EventArgs) Handles SuspendTakeAwaysCHECKBOX.GotFocus
            QuickHelpHandler("SuspendTakeAwaysCHECKBOX") : SelectedControl = "SuspendTakeAwaysCHECKBOX" : End Sub
        '
        'Suspend Attendance Checkbox
        Private Sub SuspendAttendance_DisplayQuickHelpTextOnMouseMovment(sender As Object, e As EventArgs) Handles SuspendAttendanceCHECKBOX.MouseHover, SuspendAttendanceBorderLABEL.MouseHover, SuspendAttendanceBorderLABEL.MouseEnter
            QuickHelpHandler("SuspendAttendanceCHECKBOX") : End Sub
        Private Sub SuspendAttendance_DisplayQuickHelpTextOnOnControlFocus(sender As Object, e As EventArgs) Handles SuspendAttendanceCHECKBOX.GotFocus
            QuickHelpHandler("SuspendAttendanceCHECKBOX") : SelectedControl = "SuspendAttendanceCHECKBOX" : End
        End Sub
        '
        'Create Account Checkbox
        Private Sub CreateAccount_DisplayQuickHelpTextOnMouseMovment(sender As Object, e As EventArgs) Handles CreateAccountCHECKBOX.MouseHover, CreateAccountBorderLABEL.MouseHover, CreateAccountBorderLABEL.MouseEnter
            QuickHelpHandler("CreateAccountCHECKBOX") : End Sub
        Private Sub CreateAccount_DisplayQuickHelpTextOnOnControlFocus(sender As Object, e As EventArgs) Handles CreateAccountCHECKBOX.GotFocus
            QuickHelpHandler("CreateAccountCHECKBOX") : SelectedControl = "CreateAccountCHECKBOX" : End
        End Sub
    
        'Adjustment Prescribed Checkbox
        Private Sub DoseAdjustmentPrescribed_DisplayQuickHelpTextOnMouseMovment(sender As Object, e As EventArgs) Handles DoseAdjustmentPrescribedCHECKBOX.MouseHover, DoseAdjustmentPrescribedBorderLABEL.MouseHover, DoseAdjustmentPrescribedBorderLABEL.MouseEnter
            QuickHelpHandler("DoseAdjustmentPrescribedCHECKBOX") : End Sub
        Private Sub DoseAdjustmentPrescribed_DisplayQuickHelpTextOnOnControlFocus(sender As Object, e As EventArgs) Handles DoseAdjustmentPrescribedCHECKBOX.GotFocus
            QuickHelpHandler("DoseAdjustmentPrescribedCHECKBOX") : SelectedControl = "DoseAdjustmentPrescribedCHECKBOX" : End
        End Sub

    The above code shows the four handlers that are used to display the help message I explained earlier. (remarking these out removes the shut down error)

    To explain my system quickly, there are two Handlers for each of the four checkboxes. One to trigger the help message on mouse movement, The other to trigger the help message as the checkboxes are selected.
    The HelpTextHandler(SelectedCheckboxString) the handlers call use a select case on the SelectedCheckboxString Var to update the help text Labels to the relevant message, nothing more.

    To explain The BorderLABEL controls.  I have set labels up behind and around the checkbox controls to trigger the help message as the pointer approaches the control.
    I have done this because with some controls the mouse hover or enter events wont trigger on the whole control, for example a combobox only seems to trigger when passing over the dropdown list button, and numeric up down controls also only trigger over the increment buttons. Using a label around the control ensures the help message displays no matter where the mouse pointer passes across the control.

    And I combined Mouse Hover and Mouse enter event triggers to the same handler because sometimes the mouse moves too fast to pick up one or the other events, combining the two seems to reduce this from occurring anywhere near as much.

    I have repeated this system some thirty times across controls for as many database fields. All others still seem to bee working fine.

    Also as I said earlier The two "Suspend TA's Checkbox" handlers listed above are still working as well. The other six not so much. I have set all four checkboxes up the same way so it is strange to me that one works but the others don't. The other fields and controls notwithstanding either.


    So, in summation,

    Would it be because I have combined two events of the same kind on one control (ie the mouse hover and enter events)

    Or am I, while within the event I just triggered, do I instantaneously trigger it again when switching from enter to hover events as the mouse passes over the event control? (which I think is what was meant in an above reply)

    Or am I triggering to much at one time and thus crashing the runtime logic..

    or something else please,

    Again All Help Greatly Appreciated.

    Rob












    • Edited by AussieHack Tuesday, May 23, 2017 3:06 AM Fix More Typos
    Tuesday, May 23, 2017 2:00 AM
  • Rob,

    .GotFocus is low level and MSDN documentation show that we're not to use it. I don't know that's it but use .Enter and .Leave, not .GotFocus and .LostFocus.

    *****

    Here it is:

    https://msdn.microsoft.com/en-us/library/system.windows.forms.control.gotfocus(v=vs.110).aspx

    The note shows:

    "The GotFocusand LostFocusevents are low-level focus events that are tied to the WM_KILLFOCUS and WM_SETFOCUS Windows messages. Typically, the GotFocusand LostFocusevents are only used when updating UICuesor when writing custom controls. Instead the Enterand Leaveevents should be used for all controls except the Formclass, which uses the Activatedand Deactivateevents. For more information about the GotFocusand LostFocusevents, see the WM_SETFOCUSandWM_KILLFOCUStopics."

    Also, right beneath that, look at the caution message please.


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    Tuesday, May 23, 2017 4:13 AM
  • Well Ive just made a total fool of myself... Just finally found it. Was a typo of all things. Too ashamed to really want to say what it was.

    Cant believe I missed this and that It took so long to realize it.

    The typo is clearly visible at the 'end' of every .gotfocus handler... except the one that works ofc.

    So very, very, very sorry to waist your time.

    Feeling like a fool right now. Although I have swapped the got focus handlers to enter, ty Frank.
    Sorry to waist everyone's time that replied, it was not intentional.

    Will go offline now for a bit I think.. avoid what ridicule I can, lol.

    • Marked as answer by AussieHack Tuesday, May 23, 2017 5:59 AM
    • Edited by AussieHack Tuesday, May 23, 2017 6:08 AM
    Tuesday, May 23, 2017 5:59 AM
  • Well Ive just made a total fool of myself... Just finally found it. Was a typo of all things. Too ashamed to really want to say what it was.

    Cant believe I missed this and that It took so long to realize it.

    The typo is clearly visible at the 'end' of every .gotfocus handler... except the one that works ofc.

    So very, very, very sorry to waist your time.

    Feeling like a fool right now. Although I have swapped the got focus handlers to enter, ty Frank.
    Sorry to waist everyone's time that replied, it was not intentional.

    Will go offline now for a bit I think.. avoid what ridicule I can, lol.

    No ridicule.  We all make mistakes.  If you learned something, there was no time wasted.  That's why we're here.


    Reed Kimble - "When you do things right, people won't be sure you've done anything at all"

    Friday, May 26, 2017 12:22 PM
    Moderator