locked
Windows Mobile 6.5 Menu Item Click issue causes stackoverflow exception RRS feed

  • Question

  • Hi 

    I am having a peculiar issue with menu items I dont know if anyone has noticed it. I am able to replicate the problem any no of times. Normally in WM 6 and lower versions when a menu item is disabled "MenuItem.Enable = false" this will make sure the item will become greyed out and if you click on it, it wont register the clicks. But on WM 6.5 if you disable a menu item and do some clicks after enabling it, the clicks which was registered during the disable period is activated, due to this sometime I experience stackoverflow exception because of multiple times the same method being called. I am not able to avoid this even if the menu item event is unsubscribed and subscribed back. Please if any one has any answers it will be very helpful for me and others working on WM6.5

    Regards

    Sri

     

    Tuesday, December 11, 2012 11:46 AM

All replies

  • I don't think that's the reason for it. Stack overflow commonly occurs because of infinite recursion and not because of few delayed events firing. 

    Stack trace would show how recursion happened. Please go ahead and post it.

     

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, December 11, 2012 4:46 PM
  • Hi Ilya

    Thanks for the reply. I dont think you understood what I was trying to point out. I am aware stackoverflow exception occurs due to recursive calling of a method. To prevent a user from clicking the menu item multiple times we try to disable a menu item for the particular time until the method finishes it action right but what is happening here is when the menu item is in a disable state it is recording click events if clicked on it, which doesnt happen in any of the earlier windows mobile OS. What is the use of disabling the menu item if it is recording the clicks and processing it after it gets enabled?

    Else do we need to disable it in a different way ? You wouldn't believe I have even tried unsubscribing the event totally and resubscribed it still it is processing all the clicks I have clicked when it was in the greyed out state.

    thanks

    Tuesday, December 11, 2012 5:02 PM
  • May be your are correct, may be not. Stack trace would show what exactly is going on here. So if you want help go ahead and post it (along with handler's code). Once we know what is going on we'll figure out how to fix the issue.

    In my opinion what happens is: in the event handler you're doing something which is causing event to fire again. It probably has nothing to do with few extra clicks potentially generated by user. Again, your theory is just as good as mine and stack trace/code are needed to see what is going on.

    Anyways, there's more than one way to ignore clicks. For example:

    bool _processingClick = false;

    ...

    if (!_processingClick)

    {

    _processingClick = true;

    // Do whatever here.

    _processingClick  = false;

    }

    Since UI is single threaded no need for fancy thread synchronization here.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, December 11, 2012 7:38 PM
  • I am already doing that processingClick inside my method and going one step further by disabling the menu item, showing a cursor & refreshing the screen and then processing other things which needs to be processed. I have pasted below the exception. There is a serious difference in click handling between 6.5 and the older versions. Simple thing is why is it capturing clicks when it is in disabled state ? I have tested the same code in older OS 6.1 it works fine even if I click it 10 times it doesnt register any.

    2012-12-04T10:00:47: WorkFlowScreen.menuItemLeft_Click ERROR: StackOverflowException
     STACK TRACE:    at System.Windows.Forms.Control.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.Yield()
       at CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click(Object sender, EventArgs e)
       at System.Windows.Forms.MenuItem.OnClick(EventArgs e)
       at System.Windows.Forms.Menu.ProcessMnuProc(Control ctlThis, WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Form.WnProc(WM wm, Int32 wParam, Int32 lParam)
       at System.Windows.Forms.Control._InternalWnProc(WM wm, Int32 wParam, Int32 lParam)
       at Microsoft.AGL.Forms.EVL.EnterMainLoop(IntPtr hwnMain)
       at System.Windows.Forms.Application.Run(Form fm)
       at CD.MobileI.Hht.EntryPoint.Program.Main()

    Wednesday, December 12, 2012 10:02 AM
  • Good. Now I need the handler's code. Trace it step by step and indicate the exact line which causes event to fire again.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Wednesday, December 12, 2012 4:42 PM
  • Sorry I didnt get you. I have explained myself, I think it is due to user clicking the menu multiple times when it is greyed out..

    This is the only error which is logged what does handler code mean?

    Wednesday, December 12, 2012 4:51 PM
  • Here's what I need:

    1. Put a break point in this method: CD.MobileI.Device.UI.WorkFlowScreen.menuItemLeft_Click

    2. Step it line by line using debugger.

    3. At some line method reentry would occur. Make a note of that.

    4. Post the code in the method above and mark the line at which reentry happened.

    As I explained I think it has nothing to do with user clicking the menu times when it is greyed out. Even assuming that is the case it would simply fire event as many times as user managed to click the menu (which is a few) and would not cause infinite recursion. But then again, I may be wrong which is why I needed stack trace and code.

    By the way, you seem to be reluctant to provide this information and that's fine. I will not ask for it again (nor I will be able to help).


    This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by Elegentin Xie Tuesday, December 25, 2012 3:54 AM
    • Unmarked as answer by Sri2uk Thursday, December 27, 2012 12:18 PM
    Wednesday, December 12, 2012 5:19 PM
  • I will do that thing and send you the outcome, but first can you pls explain the behaviour change in the first place. The same app runs without any issue on Windows Mobile 6.1 even when clicked multiple times. why is that? I tested both the devices at the same time with the same application version. 

    PS: Also I would like to point out that we have around 500 devices in the field running the application which are in Windows OS 6.1 and around 50 Windows OS 6.5 devices there is no problem related to this issue with the 500 devices but I get everyday one issue related to this from the 50 odd devices. 

    The devices used are MC55 and MC65 for your reference

    thx


    • Edited by Sri2uk Thursday, December 13, 2012 10:34 AM Added more info
    Thursday, December 13, 2012 10:32 AM
  • I don't know if specific behavior you mentioned is in fact different and if it is why this the change was made. If it was changed perhaps it was a bug fix, or a new bug was introduced, either in the OS or in OEM code. Or may be click is cached by the touch screen driver or something like this.

    If you want to verify this specific behavior you can create an empty app, add disabled menu item, add event handler and show dialog box from from it. Then run that and click on the disabled menu item and see if dialog box would appear. Probably it won't, but if it does then call official support and let them investigate the problem using the repro app you created.

    In any case, in my opinion whatever or not it worked before is not relevant. The fix is unlikely and it would take a very long time to get through the OEM. So the task at hand should be this: how to make it work with what we have. 

    For starters I would suggest trying a code snippet I posted above, it probably would take care of the issue without any investigation on your part. Just wrap your code into it and be done. Should be compatible with the previous OS versions as well.


    This posting is provided "AS IS" with no warranties, and confers no rights.

    • Marked as answer by Elegentin Xie Tuesday, December 25, 2012 3:51 AM
    • Unmarked as answer by Sri2uk Thursday, December 27, 2012 11:26 AM
    Thursday, December 13, 2012 5:22 PM
  • Hi Thanks for the reply 

    I have already done that test which you mentioned if I introduce a messagebox then the event only misfires once and then all the under lying events disappear. I even tried putting message box on the main application and giving it to the end user to test they are quite annoyed seeing the message box coming up every time they have clicked the menu when it is greyed out by mistake. So that's why I came and posted my query on this forum. I will keep you posted 

    Also I would like to mention that the camera is crashing due to this issue sometime the whole app crashes without even logging any error cant even see the windows error which pops up when a crash happens. 

    thanks

    Thursday, December 13, 2012 5:30 PM
  • Hi,

    I have marked Iiya's reply as answer.
    If you disagree, please unmark it, and post your doubt.

    Regards,


    Elegentin Xie
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, December 25, 2012 3:54 AM
  • Hi 

    I am trying to prove that their seems to be a major bug in Windows Mobile 6.5 compare to WM 6.1 I have done all the necessary tests to replicate it. I would be happy if a solution is suggested.

    thanks

     

    Thursday, December 27, 2012 11:28 AM
  • Did you try the solution I suggested above?


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, December 27, 2012 5:02 PM
  • Yes I already replied on Dec 13 about it. 
    Thursday, December 27, 2012 5:15 PM
  • Your replay states something about adding message boxes for diagnostics purpose. I'm talking about this change:

    bool _processingClick = false;

    ...

    if (!_processingClick)

    {

    _processingClick = true;

    // Do whatever here.

    _processingClick  = false;

    }

    Did you try this one? Just to clarify, you need to add a member variable in your form's class and wrap the code in the problematic event handler into the 'if' statement provided. 

    Also you did not posted your code. If you not going to try suggested solutions and provide necessary information I just can't help you and there's no point to continue. Good luck!


    This posting is provided "AS IS" with no warranties, and confers no rights.

    Thursday, December 27, 2012 8:24 PM
  • Please see my code below. I am doing your suggestion already.

     private void menuItemLeft_Click(object sender, EventArgs e)
            {
                try
                {
                    if (!_processing)
                    {
                        _processing = true;
                        Cursor.Current = Cursors.WaitCursor;

                        AuthenticateUser();

                        Cursor.Current = Cursors.Default;
                        _processing = false;
                    }
                }
                catch (Exception ex)
                {
                    LoggingHelper.Instance.TraceException(_thisClassName, MethodName, ex);
                }
            }

    Thursday, December 27, 2012 10:29 PM