MapPoint Forums

MapForums

Community of MapPoint and Virtual Earth Users and Developers




Solution: Server busy window after popup context menu.

This is a discussion on Solution: Server busy window after popup context menu. within the MapPoint 2006/2009 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 ...


Go Back   MapPoint Forums > Map Forums > MapPoint 2006/2009 Discussion

Today's Posts Twitter Feed Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack (1) Thread Tools Display Modes
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 04-05-2005
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #2 (permalink)  
Old 04-05-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,177
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 !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3 (permalink)  
Old 04-05-2005
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)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4 (permalink)  
Old 04-05-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,177
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5 (permalink)  
Old 04-06-2005
Junior Member
Yellow Belt
 
Join Date: Feb 2005
Posts: 19
Quote:
I hope my explanation make sence Smile
Yeah it really is

Thanks for your good explanation!
bye
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6 (permalink)  
Old 04-06-2005
Winwaed's Avatar
Mapping-Tools.com
Black Belt
 
Join Date: Feb 2004
Posts: 1,142
Blog Entries: 22
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
See the Geoweb Guru for online mapping
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7 (permalink)  
Old 04-06-2005
Senior Member
Black Belt
 
Join Date: Nov 2004
Posts: 2,177
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
busy, context, menu, popup, server, solution, window


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/solution-server-busy-window-after-popup-context-menu-4044.html

Posted By For Type Date
night.swimmer's bookmarks tagged with "mappoint" on del.icio.us This thread Refback 06-20-2008 09:45 AM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Disable Context menu Anonymous MapPoint 2006/2009 Discussion 12 12-23-2008 12:05 PM
looking for Delphi solution for the "Server Busy" schuchhardp MapPoint 2006/2009 Discussion 8 10-20-2008 04:04 AM
Custom context menu Anonymous MapPoint 2006/2009 Discussion 3 09-10-2004 10:15 PM
Disable Mappoin 2002 PopUp Menu (using Vb.net) Anonymous MapPoint 2006/2009 Discussion 0 08-19-2003 09:12 AM
Is there any way to disable Mappoint 2002 popup menu? Anonymous MapPoint 2006/2009 Discussion 2 12-12-2002 05:21 PM


All times are GMT -5. The time now is 05:51 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 RC2
MP2K Magazine
Visitor Map

Bodrum Holiday
Check out the picturesque towns on your Bodrum holiday... Book through UlookUbook!



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