Select to view content in your preferred language

console app using GeoProcessor managed assembly won't exit

1785
5
Jump to solution
06-12-2013 09:38 AM
TedRakel
Deactivated User
I have a windows console application written in c# that uses a geoprocessor managed assembly.  An example of how to do this is at http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000003rr000000 
I find that in the Visual Studio 2010, the console app runs to completion and exits.  If I run the console application on a command line on the same machine, the console application will not exit.  I've narrowed it down to calling GP.Execute. If this doesn't get called, then the application exits as expected when run on a command line.  I even put in code to call Process.Kill in order to terminate the process when it's done and this does not work.  I have to kil it using task manager.

Is there something not documented at http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#//0001000003rr000000 that I need to do with the GeoProcessor object in order to allow the process to terminate? 

I know it's easier to see the code, so I'm working on putting together a very small console app that demonstrates this behavior so I can post the code for everyone to see.
1 Solution

Accepted Solutions
TedRakel
Deactivated User
I took STAThread attribute off the Main method of the console app and it exits cleanly now.

View solution in original post

0 Kudos
5 Replies
TedRakel
Deactivated User
I'm still working on getting a small console app that shows the problem.  However, I was able to find that the console application will exit and not hang if I make one small change to the code.  In my application, I'm using the "DataManagementTools.Project" object in order to project a feature class in sde into a file geodatabase.  If I change the input dataset from a connection to an sde instance to a feature class in a file geodatabase, then the application will exit when it is done.  Unfortunately, this isn't what I need.  But the problem does seem to be that the input dataset to the DataManagementTools.Project object is a connection to an sde instance.  If I leave everything else the same, and only change this from an sde connection to a feature class in a file geodatabase, then the application will exit and not hang.

So it appears that there is something about using an sde connection with the GeoProcessor object or the DataManagementTools.Project object that is preventing the console application from ever exiting.  I have to use task manager to kill it.
0 Kudos
TedRakel
Deactivated User
Here's more detail on what I found. 

DataManagementTools.Project projectFC = new DataManagementTools.Project();
//this causes the console app to never exit
projectFC.in_dataset = "Database Connections\\Connection to orct.apollo tlgis.sde\\TLGIS.TL_STRUCTURE_TEN";

//this does not cause the console app to never exit
projectFC.in_dataset = @"C:\temp\CreateTL_PUB01_FGDB\CreateTL_PUB01_FGDB\bin\Debug\source.gdb\TL_STRUCTURE_TEN";

So using an input dataset from sde causes the console app to never exit, but using an input_dataset from a file geodatabase does not cause the console app to never exit.  All other lines of code remain the same.
TedRakel
Deactivated User
I attached to the console app when it appeared hung with visual studio and broke into it.  Here's the call stack
It appears that GeoProcessor is trying to shut down and is hanging in the attempt.


> ntdll.dll!_NtWaitForSingleObject@12()  + 0x15 bytes
  ntdll.dll!_NtWaitForSingleObject@12()  + 0x15 bytes
  kernel32.dll!_WaitForSingleObjectExImplementation@12()  + 0x43 bytes
  kernel32.dll!_WaitForSingleObject@8()  + 0x12 bytes
  sde.dll!_CMEM_data_waiting()  + 0xa6 bytes
  sde.dll!_CMEM_write_long()  + 0x3d bytes
  sde.dll!_CH_write_command()  + 0x9b bytes
  sde.dll!_SES_srvr_command()  + 0x11 bytes
  sde.dll!_SE_state_free_lock64_API@12()  + 0x71 bytes
  sde.dll!_SE_state_free_lock64@12()  + 0x12a bytes
  sde.dll!_SE_state_free_lock@8()  + 0x11 bytes
  SdeFDB.dll!5c620c9f() 
  [Frames below may be incorrect and/or missing, no symbols loaded for SdeFDB.dll]
  SdeFDB.dll!5c5f396f() 
  SdeFDB.dll!5c5d37fa() 
  SdeFDB.dll!5c5d344b() 
  SdeFDB.dll!5c64591e() 
  SdeFDB.dll!5c5c0a91() 
  GpObjects.dll!DEUtilities::ClearWorkspaceCache()  + 0x7d bytes
  GpObjects.dll!DEUtilities::ReleaseInternals()  + 0x23 bytes
  GpObjects.dll!GPUtilities::ReleaseInternals()  + 0x11e bytes
  GeoProcessor.dll!GeoProcessorOPs::Shutdown()  + 0x1fb bytes
  GeoProcessor.dll!GeoProcessorOPs::~GeoProcessorOPs()  + 0x7c bytes
  GeoProcessor.dll!GeoProcessorOPs::`vector deleting destructor'()  + 0xc bytes
  GeoProcessor.dll!Unknown::InternalRelease()  + 0x2e bytes
  GeoProcessor.dll!GeoProcessorEventsHelper3::Release()  + 0x11 bytes
  GeoProcessor.dll!GPHolder::~GPHolder()  + 0x50 bytes
  GeoProcessor.dll!GPHolder::`scalar deleting destructor'()  + 0xc bytes
  GeoProcessor.dll!Unknown::InternalRelease()  + 0x2e bytes
  GeoProcessor.dll!GeoProcessorEventsHelper3::Release()  + 0x11 bytes
  GeoProcessor.dll!SingletonClassFactory<GPHolder>::ReleaseInstanceIfUnused()  + 0xab bytes
  GeoProcessor.dll!SingletonClassFactory<GPHolder>::~SingletonClassFactory<GPHolder>()  + 0x46 bytes
  GeoProcessor.dll!SingletonClassFactory<GPHolder>::`vector deleting destructor'()  + 0xb bytes
  GeoProcessor.dll!ClassFactory<GeoProcessorEventsHelper3>::Release()  + 0x27 bytes
  GeoProcessor.dll!ComponentInfo::~ComponentInfo()  + 0x15 bytes
  GeoProcessor.dll!`eh vector destructor iterator'()  + 0x2e bytes
  GeoProcessor.dll!`DECoreUtil::GetAppsInstallPath'::`2'::`dynamic atexit destructor for 'installPath''()  + 0x53 bytes
  GeoProcessor.dll!__CRT_INIT@12()  + 0x1be bytes
  GeoProcessor.dll!__CRT_INIT@12()  + 0x2dd bytes
  GeoProcessor.dll!__DllMainCRTStartup@12()  + 0x1e bytes
  ntdll.dll!_LdrpCallInitRoutine@16()  + 0x14 bytes
  ntdll.dll!_LdrShutdownProcess@0()  + 0x141 bytes
  ntdll.dll!_RtlExitUserProcess@4()  + 0x74 bytes
  kernel32.dll!75227a0d() 
  mscorwks.dll!SafeExitProcess()  + 0xb7 bytes
  mscorwks.dll!DisableRuntime()  - 0x1781e0 bytes
  mscoreei.dll!RuntimeDesc::ShutdownAllActiveRuntimes()  + 0x873e bytes
  mscoreei.dll!CLRRuntimeHostInternalImpl::ShutdownAllRuntimesThenExit()  + 0x15 bytes
  clr.dll!EEPolicy::ExitProcessViaShim()  + 0x66 bytes
  clr.dll!SafeExitProcess()  + 0x99 bytes
  clr.dll!DisableRuntime()  - 0x145a53 bytes
  clr.dll!EEPolicy::HandleExitProcess()  + 0x57 bytes
  clr.dll!__CorExeMainInternal@0()  + 0x11c bytes
  clr.dll!__CorExeMain@0()  + 0x1c bytes
  mscoreei.dll!__CorExeMain@0()  + 0x38 bytes
  mscoree.dll!_ShellShim__CorExeMain@0()  + 0x227 bytes
  mscoree.dll!__CorExeMain_Exported@0()  + 0x8 bytes
  kernel32.dll!@BaseThreadInitThunk@12()  + 0x12 bytes
  ntdll.dll!___RtlUserThreadStart@8()  + 0x27 bytes
  ntdll.dll!__RtlUserThreadStart@8()  + 0x1b bytes
0 Kudos
TedRakel
Deactivated User
I took STAThread attribute off the Main method of the console app and it exits cleanly now.
0 Kudos
nishadwijesekara
Deactivated User

Taking off STAThread is not the solution, it will seriously impact the application to be thread unstable and impact the performance a lot. The solution to this is to properly execute the GeoProcessing tools. Within this module, assign NULLs and release all objects properly. I had this problem for awhile, and this resolved my issue with running GeoProcessing tools within my Console Application.

public static void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC)

{

// Set the overwrite output option to true

geoprocessor.ClearMessages();

geoprocessor.OverwriteOutput = true;

// Execute the tool

try

{

geoprocessor.Execute(process, null);

ReturnMessages(geoprocessor);

geoprocessor = null;

process = null;

ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(geoprocessor);

ESRI.ArcGIS.ADF.ComReleaser.ReleaseCOMObject(process);

}

catch (Exception err)

{

ReturnMessages(geoprocessor);

}

}

0 Kudos