Is it possible to extend timeout for BasicRequest object

Apr 9, 2012 at 3:08 PM

I'm using the BasicRequest class to get tiles from a private tile server (with a URL template) feeding into the SharpMap class.  This is working but due to a terribly underpowered system driving the tile server I'm seeing quite a few request timeouts.  When a timeout occurs it leaves an artifact in the generated map.  If I rerun the map generator it will usually get further each time as I'm using FileCache to store the retrieved tiles and don't have to reload ones which succeeded earlier.

Is there a way to either extend the timeout when using the BasicRequest object or to detect when a timeout has occurred so that I can automatically retry the request to get any missing tiles?


Apr 9, 2012 at 9:23 PM

You can put the tile request in a try catch block and count the retries. In Mapsui I use a Dictionary<TileIndex, int> to keep track of retries. You could use several parallel request to speed up the process.

You can set a static Timeout member on the static RequestHelper.

Hope this helps

Apr 10, 2012 at 10:28 AM

Sorry, but I'm probably a bit thick at 6:00 AM before a couple of cups of coffee.  I like both of the ideas you mention above but I've been unable to find a timeout property on either the static RequestHelper class or an instance of the class.  As for the try/catch, I really would like to do something along these lines but I don't see where I can wire it in.  The exceptions do not bubble up through the SharpMap library to the user call and I don't see where I can attach a delegate call to the BasicRequest object (or any of the SharpMap objects) which could be used to see the exception and handle it.

For reference, here is how my request is currently formatted:

var map = new Map(new Size(_width, _height));

var request = new BasicRequest(_urlTemplate);
var fileCache = new FileCache(_tileCacheFolder, "png");
var tileSource = new (TileSource(
    new WebTileProvider(request, fileCache, _userAgent, _referer, false),
    new SphericalMercatorInvertedWorldSchema());
var tileLayer = new TileLayer(tileSource, "BaseLayer");


Thanks for any guidance you can provide to point me in the right direction.

Apr 10, 2012 at 10:57 AM

The Timeout was added quite recent. You probably use an older version of BruTile. 

I am not sure what your architecture is. You mention 'If I rerun the map generator', so I assume you do not use SharpMap purely as a mapping client. Is this some tool you building? How does it work?

Apr 10, 2012 at 12:21 PM

I'm using, which is what comes with the current release of SharpMap.  I'll have to see if SharpMap will play nice with the newer version.

As for how I'm using this, I have a web application which collects a list of points with different color markers and labels.  The end product is a PDF document for printing.  The helper class I'm building takes a collection of markers, builds a map, drops it into a PDF document, and returns that as a byte array to be streamed back out to the browser.  To rerun the generator I just re-request the same page.  

Once the tile cache has populated the document is generated nice and fast.

Apr 10, 2012 at 12:58 PM

You will have to update SharpMap to use the new BruTile version. If you go down that route you could customize TileLayer for your needs.

Alternatively you could keep SharpMap/BruTile as is and try to create you own CustomTileLayer by copying the code from the original:

into a CustomTileLayer.cs in your own project. And then add a try/catch there.

I am not sure if there is no use of internal/private classes, but you will find that out soon.

Perhaps you could also reduce the number of parallel threads of ThreadPool to reduce the load on your server (perhaps this should be the first thing to do).