Declined
Last Updated: 16 Feb 2021 13:17 by ADMIN
Trung
Created on: 10 Feb 2021 15:07
Category: Map
Type: Bug Report
0
RadMap: Error message occurs when deleting the images used in a LocalMapProvider

Run the attached project and follow the steps in the gif file. As a result the following exception occurs:

System.IO.IOException: 'The process cannot access the file 't_0_0_1.png' because it is being used by another process.'

1 comment
ADMIN
Dimitar
Posted on: 16 Feb 2021 05:25

Hello,

This is not an issue in the controls. We are loading the tile images with the Microsoft Image.FromFile method. Loading images from the file system may lock the files on some Windows systems.  The same error can be reproduced in a similar scenario in an empty form without the RadMap control.

The scenario in the project requires to delete the images from the file system as soon as the  form with the map closes. A custom map provider loading the images as Bitmaps can help:

public class CustomLocalMapProvider : LocalMapProvider
{
    public override Image LoadTile(int x, int y, int zoom)
    {
        string key = Path.Combine(this.DirectoryPath, string.Format(this.FileFormat, x, y, zoom));
        Image tile;

        if (File.Exists(key))
        {
            using (var bmpTemp = new Bitmap(key))
            {
                tile = new Bitmap(bmpTemp);
            }
        }
        else
        {
            tile = this.NoImageAvailable;
        }

        return tile;
    }
}

It is also necessary to call the map`s Dispose method when closing the form.

Regards,
Dimitar
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.