We are using 362. Our users can click a button on our dialog that causes a map to feature datasource to get retrieved from our database and then drawn as a map layer. We spin the wait cursor through the process of retrieving the data and updating the overlay. Then, our client is done, and the background threads of MapSuite take over. Rendering this layer, unfortunately take about 5 seconds... just due to the nature of the data. Do I have any way of knowing that the map is working? Is there an event to let me know a background drawing thread has started and/or stopped? Is there any other way for me to provide feedback that the map will be forthcoming?
Wait cursor during rendering
Ted,
Thanks for your post and questions!
There are two events which indicts the drawing in another thread starts or stops.
Map.OverlaysDrawing +=new EventHandler<OverlaysDrawingWinformsMapEventArgs>(Map_OverlaysDrawing);
Map.OverlaysDrawn +=new EventHandler<OverlaysDrawnWinformsMapEventArgs>(Map_OverlaysDrawn);
While there is one thing we should pay attention to, this event is fired in another threading, so if you want to access the resources in main threading, you have to use invoke to make it executed in main threading.
private void Map_OverlaysDrawn(object sender, ThinkGeo.MapSuite.DesktopEdition.OverlaysDrawnWinformsMapEventArgs e)
{
ChangeCursor changeCursor = new ChangeCursor(ChangeCursorAfterDrawing);
this.BeginInvoke(changeCursor);
}
private void ChangeCursorAfterDrawing()
{
this.Cursor = Cursors.Default;
}
For more detailed information, you can reference the codes in WorldMapKit Desktop sample.
Any more questions feel free to let me know.
Thanks.
Yale
Hi!
I’m looking for the same thing but, I can’t find the ChangeCursor class. Im using vb.ner and the latest version of MapSuite. is only available on certain realeses or where??
thanks a lot!!
Miren,
The sample was incomplete. It was missing one critical line of code which was the creating of the delegate. You can see the code below which you need to put as a member variable in the class that uses the function. What happens is that the delegate is a gateway into the ChangeCursorAfterDrawing method. We create the delegate and in the constructor we pass the function name we want that gateway to point to. Next we call the BeginInvoke which will call that gateway ie calling the ChangeCursorAfterDrawing but on the main thread. These delegates are necessary when you want to make calls between threads using the Invoke methods. Anyway more information than you probably needed but I hope that helps.
private delegate void ChangeCursor();
David
Thanks a lot David!!
I didn’t know how to work with delegates
Miren,
They are mind bending at first but I like to think of them as little gateways or portals. Anyway they are really powerful for calling arbitrary functions at run-time. Pretty cool stuff, when you get a chance check out some documentation on them, they are worth knowing about as they can save your life sometimes.
David
Hi again!!
I used it and it worked fine but now I have another problem. I get an ObjectDisposedException when, after been hidden, I try to show the form again. Any ideas of why and how can I avoid it??
Thanks a lot!!
Miren,
We can not recreate your exception.
Can you show us the detail things about the exception? For example, you can put the description of it or paste the stack trace to us.
If you create a sample to show this problem will be more helpful.
Thanks.
James