Ben Ben - 1 year ago 197
C# Question

DevExpress Map Control not Loading - Windows Service

I am using the DevExpress XtraMap MapControl within a windows service with the intention of generating the maps, saving them as images and adding them to reports. I have this setup working well when using it through a WinForms project, but when I copy the same code to a Windows Service it fails to save the image. Code in the WinForms project:

MapControl map;
public void Form1_Load_1(object sender, EventArgs e)
// Create a map control.
map = new MapControl();

// Create an image tiles layer and add it to the map.
ImageTilesLayer tilesLayer = new ImageTilesLayer();
tilesLayer.DataLoaded += Map_DataLoaded;

BingMapDataProvider prov = new BingMapDataProvider();
prov.BingKey = "MY_BING_KEY";
tilesLayer.DataProvider = prov;

map.ZoomLevel = 2;
map.CenterPoint = new GeoPoint(38, -100);



private void Map_DataLoaded(object sender, EventArgs e)
var loc = @"C:\0Temp\Map\" + DateTime.Now.Ticks.ToString() + ".png";
map.ExportToImage(loc, System.Drawing.Imaging.ImageFormat.Png);

This code when run in a Windows service fails to save the image. The only difference being, in the Windows Service, the following line is removed:


When removing that line from the winforms project, it also fails to load/save. I can only assume that there is an event being triggered/monitored that adding this control to a form triggers that I am not aware of?

Answer Source

I believe, the Map Control is not intended to be used without showing it (or at least without creating it's handle). So when accessing to Bing Maps from Windows-service, I suggest you to use the Bing Imagery API directly.

p.s. Microsoft Bing Maps Terms of Use do not allow to

3.2 (b) Copy, store, archive, or create a database of the Content ...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download