Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe
Results 1 to 7 of 7

Solution: Server busy window after popup context menu.

This is a discussion on Solution: Server busy window after popup context menu. within the MapPoint Desktop Discussion forums, part of the Map Forums category; Hi, I that a lot users on the forum have this problem. When you popup a context menu, or some ...

  1. #1
    Jeurink is offline Junior Member Yellow Belt
    Join Date
    Feb 2005
    Posts
    19

    Solution: Server busy window after popup context menu.

    Hi, I that a lot users on the forum have this problem.

    When you popup a context menu, or some dialog from an event fired from MapPoint, you get a "Server busy" message after 10 seconds. Realy annoying, it allways happens when you demo your code to your boss.

    I found my own (imho nicer than sending "esc" char after 9 seconds) solution. You can have your context menu longer open than 10 seconds without problems.

    This solution is for C# (so .NET), but it it is just the concept.

    Make a timer that sets off after 1 msec. and two variables that hold the mouse position.

    Code:
    private System.Windows.Forms.Timer showContextMenuTimer;
    private int mouseYloc, mouseXloc;
    
    // This timer is used to popup a context menu, when
    // an user has right clicked a symbol on the map
    showContextMenuTimer = new Timer();
    showContextMenuTimer.Tick+=new EventHandler(showContextMenuTimer_Tick);
    showContextMenuTimer.Interval=1;
    Event handler:
    Code:
    private void showContextMenuTimer_Tick(object sender, EventArgs e)
    {
    	showContextMenuTimer.Stop();
             // insert your contextMenu.show routine here...
    	subscriberMenu.Show(this,new Point(mouseXloc+180,mouseYloc+10));
    
    }
    When you want to popup a context menu, you simple call
    showContextMenuTimer.Start();

    Code:
    private void axMappointControl1_BeforeClick(object sender, AxMapPoint._IMappointCtrlEvents_BeforeClickEvent e)
    {
    	if(e.button==2) // right click
    	{
    		e.cancel=true;
    		mouseXloc = e.x; // used in the Timer.Tick event
    		mouseYloc= e.y;
    		showContextMenuTimer.Start();
    	}
    }
    The problem is (I think) that the contextMenu.show call doesn't return before those 10 seconds. By opening it from a serparate thread it returns immediatly.

    have fun with it!

  2. #2
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    Thanks for feedback
    Yes this is a good idea. The problem is not threading, the timer's tickis executed in same thread context, but the difference is that the code is executed outside the event.

    This explains more. A menu is nothing else than a modal form, so displaying a modal form in the event will block mappoint. So when you do it outside it then all is ok.

    wonderfull idea

    A better approach should be to not use a timer but post a message to the form with the x, y parameters. In de WndProc method there you pop the menu . If someone wants example I be glad to post it of course !

  3. #3
    Jeurink is offline Junior Member Yellow Belt
    Join Date
    Feb 2005
    Posts
    19
    Hmm, if it is not too much work, could you post an example?

    I'm not really understanding what you mean with "post wndproc message to the form".
    (I've learned java and standard c++ so i'm not really into window messages)

  4. #4
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi,

    Ok here is example and I try to explain (my english is not so well

    The whole windows thing is based on messages. When you move your mouse over a form thousands of them are sent to it with the x,y coordinates, same if you pull down a button on keyboard and if you lose it again. Messages are handled by each window by a so called message pump. Now you can also make custom message handlers. That is message handlers that does what you want. You need many times execute code outside of a loop or ouside an event (what we are gonna do).

    Also it is "the" system if you are in a thread and you want code execute in the thread context of a particular window that is created in another therad. A good example is the User interface.

    There are 2 importand ones, that is SendMessage and PostMessage. Both are doeing the same with the difference that SendMessage will block the thread until the custom message handler has finished while PostMesage is async and will return immediatly. In both of the code will execute as soon as the destination start pumping messages.

    So we define first our message. It has to be > WM_USER witch is 0x400.:

    Code:
            const int WM_POPUPMENU = 0x401;
    Now we override the WndProc of the form. This is part of the message pump and is called by the message pump itselfL:

    Code:
            private void popup(IntPtr x, IntPtr y)
            {
                // here you popup your menu
            }
    
            protected override void WndProc(ref Message m)
            {
                switch (m.Msg) {
                    case WM_POPUPMENU:
                        popup(m.WParam, m.LParam);
                        break;
                    default:
                        base.WndProc(ref m);
                        break;
                }
            }
    You have to make sure that you trap all exceptions, because if an execption comes here it is dramaticly;because it comes from the middle of nowhere cleaning the call stack means kill your program... Also be aware that this function is called thousands of times a second. So you dont wat to put slow code in it, so always optimize it for speed.

    and in the BeforeClick you post the message:

    Code:
            private void MP_BeforeClick_1(object sender, AxMapPoint._IMappointCtrlEvents_BeforeClickEvent e)
            {
                Win32.PostMessage(Handle, WM_POPUPMENU, e.x, e.y);
    Now we need to define thw win32 API call, and do it as sutch:

    Code:
        public class Win32
        {
            [DllImport("User32.dll")]
            public static extern Boolean PostMessage(IntPtr hWnd, uint Msg, int wParam, int lParam);
    So what happens is following:
    - beforclick post the message, since postmessage is async the event handler continue his work until it end
    - then the form start pumping messages again (because noting of your code is running)
    - the custom mssage handler is called and the window pups up

    I hope my explanation make sence

  5. #5
    Jeurink is offline Junior Member Yellow Belt
    Join Date
    Feb 2005
    Posts
    19
    I hope my explanation make sence Smile
    Yeah it really is

    Thanks for your good explanation!
    bye

  6. #6
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    The original timer method is useful for VB though, I use this to fake multi-threading for batch processing in an add-in.



    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  7. #7
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433
    Hi Richard,

    Quote Originally Posted by Winwaed
    The original timer method is useful for VB though
    Yes but timers are limited recource. Posting a message is unlimited, take no recourse and is normal windows behavioure. And I'm sure in VB it is possible to call Win32 API call also

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Disable Context menu
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 12
    Last Post: 12-23-2008, 01:05 PM
  2. looking for Delphi solution for the "Server Busy"
    By schuchhardp in forum MapPoint Desktop Discussion
    Replies: 8
    Last Post: 10-20-2008, 05:04 AM
  3. Custom context menu
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 09-10-2004, 11:15 PM
  4. Disable Mappoin 2002 PopUp Menu (using Vb.net)
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 08-19-2003, 10:12 AM
  5. Is there any way to disable Mappoint 2002 popup menu?
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 2
    Last Post: 12-12-2002, 06:21 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96