swAddin 2011 Template (RPC_E_WRONG_THREAD)

vb.net

This is the error I get in my Try Catch... when I close Solidworks.

System.InvalidCastException: Unable to cast COM object of type 'System.__ComObject' to interface type 'SolidWorks.Interop.sldworks.ModelDoc2'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{B90793FB-EF3D-4B80-A5C4-99959CDB6CEB}' failed due to the following error: The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)).

   at MyAddin.SwAddin.DetachEventHandlers()

Can someone help me ?

SolidworksApi macros