views:

116

answers:

1

I am trying to use ArcFM with my ArcGIS project, and I've noticed a bug. If my main thread is marked with the [STAThread] attribute, the program hangs on exit with the OS Loader Lock exception. When I remove that attribute the program ends just fine.
The following code hangs

[STAThread]
private static void Main()
{
    MMAppInitialize mmAppInitialize = new MMAppInitialize();
    mmAppInitialize.IsProductCodeAvailable(mmLicensedProductCode.mmLPDesigner);
}

Anyone here have seen it before? Is there something I am doing wrong?
I figured I have to run on STAThread, since otherwise all my COM invocations will be marshalled to a different thread from the main.

A: 

Found my bug -
This will work fine:

[STAThread]
private static void Main()
{
    MMAppInitialize mmAppInitialize = new MMAppInitialize();
    mmAppInitialize.IsProductCodeAvailable(mmLicensedProductCode.mmLPDesigner);
    mmAppInitialize.Initialize(mmLicensedProductCode.mmLPDesigner);
    mmAppInitialize.Shutdown();
}

There is still a small bug - This doesn't work:

[STAThread]
private static void Main()
{
    MMAppInitialize mmAppInitialize = new MMAppInitialize();
    mmAppInitialize.IsProductCodeAvailable(mmLicensedProductCode.mmLPDesigner);
    mmAppInitialize.Shutdown();
}

Though this is not a real usecase - just checking for a license, without getting it.

In my "real" code I was calling the Initialize and finally Shutdown, but I got the LoaderLock exception because I was shutting down the mmAppInitialize after the aoAppInitialize. After switching the order, the program terminated properly.

Noam Gal