'ESRI License Initializer generated code. If (Not m_AOLicenseInitializer.InitializeApplication(New esriLicenseProductCode() {esriLicenseProductCode.esriLicenseProductCodeAdvanced}, _ New esriLicenseExtensionCode() {})) Then Console.WriteLine(m_AOLicenseInitializer.LicenseMessage()) Console.WriteLine("This application could not initialize with the correct ArcGIS license and will shutdown.") m_AOLicenseInitializer.ShutdownApplication() Return End If ' ' Initialize the Geoprocessor ' GP = New ESRI.ArcGIS.Geoprocessing.GeoProcessor() gputilities = New GPUtilitiesClass() ' ' Read App settings ' prefixOutput = System.Configuration.ConfigurationManager.AppSettings.Item("prefixOutput") prefixOutputOwner = System.Configuration.ConfigurationManager.AppSettings.Item("prefixOutputOwner") outputFC = System.Configuration.ConfigurationManager.AppSettings.Item("outputFC") ' FFeature class pathOutput = prefixOutput & prefixOutputOwner & outputFC ' ' create points ' Console.WriteLine("Start") Try ' pathOutput = SDE Feature Class where the program creates points pFeatureClass = gputilities.OpenFeatureClassFromString(pathOutput) Console.WriteLine("Create Points") ' CreatePoints() pFeatureClass = Nothing Catch ex As Exception End Try m_AOLicenseInitializer.ShutdownApplication() Console.WriteLine("End")
Thank you for your answer Domenico. But how do you fix the problem of the Console Window that does not close when running the application as a stand alone .exe with STA instead of MTA? Is there a solution using STA in 10.1 or is it a bug?Regards
But remember that:In the Single-Threaded Apartment (STA), a single thread is dedicated to execute the methods of the object. In such an arrangement, method calls from threads outside of the apartment are marshalled and automatically queued by the system (via a standard Windows message queue). Thus, the COM run-time provides automatic synchronization to ensure that each method call of an object is always executed to completion before another is invoked. The developer therefore does not need to worry about thread locking or race conditions.In the Multiple Threaded Apartment (MTA), the COM run-time provides no synchronization, and multiple threads are allowed to call COM objects simultaneously. COM objects therefore need to perform their own synchronization to prevent simultaneous access from multiple threads from causing a race condition. Calls to an MTA object from a thread in an STA are also marshaled.and model ArcObjects threading model: http://resources.esri.com/help/9.3/arcgisengine/dotnet/2c2d2655-a208-4902-bf4d-b37a1de120de.htmAs an ArcObjects developer, this means that if your application is not initialized as a single threaded application, the .NET framework will create a special single threaded apartment (STA) thread for all ArcObjects since they are marked as STA. This will cause a thread switch to this thread on each call from the application to ArcObjects. In turn, this forces the ArcObjects components to marshall each call, and eventually it may be about 50 times slower for a call to the COM component. Fortunately, this can be avoided by simply marking the main function as [STAThread].
[C#] namespace ConsoleApplication1 { class Program { [STAThread] static void Main(string[] args) { // ... } } }
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.