ThinkGeo.com    |     Documentation    |     Premium Support

WpfMap Dispose on GC Finalizer Thread

Hi,

I’m disposing ThinkGeo.MapSuite.WpfDesktopEdition.WpfMap object in a WPF User control and getting the following exception: “The calling thread cannot access this object because a different thread owns it.”

This happens because WpfMap is not being dispose on UI thread but on GC Finalizer Thread.

Shouldn’t, in theory, disposing an object be thread independent? It’s impossible to know which thread is going to call Dispose method. How to solve this issue?

Hi Tiago,

I tried to call the map.Dispose() before map.Refresh() and after map.Refresh(), but I was unable to recreate this issue.

Could you please provide us a sample to recreate this issue?

Thanks,
Peter

Hi,

Just call dispose on another thread.
In my example I have a wpf user control that implements IDisposable and it’s Dispose() method calls WpfMap.Dispose(). This means the GC Finalizer Thread will call Dispose method on this UC.

Hi Tiago,

I got the same exception when dispose the map in the other thread.

Shouldn’t, in theory, disposing an object be thread independent?

As we know that all the variables are shared between threads, if one UI variable is used by one thread and the other thread want to dispose it, in this case it throws the exception as we encountered.

How to solve this issue?

The map is the UI control, please try calling the dispose method in the UI thread.

Thanks,
Peter