Select to view content in your preferred language

Unable to dispose of AxToolbarControl

776
1
07-29-2010 09:41 AM
ESRICustomer
Occasional Contributor
In my app, I have a toolbarcontrol, the table of contents control, and the map control.
For some reason the toolbar control will not allow itself to be disposed of. I can set the reference to Nothing, but I cannot call dispose on it, and any attempt to do so throws the "InvalidOperationException" with the message...

Cross-thread operation not valid: Control 'esriMapControl' accessed from a thread other than the thread it was created on.

My code is simply this...

Me.esriToolbarControl.Dispose()
Me.esriTOCControl.Dispose()
Me.esriMapControl.Dispose()

I am also not allowed to do this...

System.Runtime.InteropServices.Marshal.FinalReleaseComObject(esriToolbarControl.GetOcx)

Any idea how to get around this?
By the way, the Table of contents control and map control can be disposed of just fine.
0 Kudos
1 Reply
ESRICustomer
Occasional Contributor
Nevermind, I found the problem.  Turns out you have to dispose of the map control BEFORE you dispose of the toolbar control.
0 Kudos