18.04.2015 Views

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

ArcGIS Engine Developer Guide

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

.NET APPLICATION PROGRAMMING INTERFACE<br />

ESRI.<strong>ArcGIS</strong>.Utility.COMSupport.AOUninitialize.Shutdown()<br />

This section does not address licensing considerations<br />

and is intended only to illustrate the<br />

possibilities of server application development<br />

using the .NET API. While the <strong>ArcGIS</strong> <strong>Engine</strong><br />

<strong>Developer</strong> Kit can be used to develop applications<br />

that run on single-use computers and that<br />

may or may not leverage ArcSDE-, <strong>ArcGIS</strong><br />

Server-, or ArcIMS-based services, custom<br />

components deployed on a server require an<br />

<strong>ArcGIS</strong> Server license. Contact your ESRI<br />

regional office or international distributor for<br />

more information.<br />

Extending the server<br />

When using .NET to create a COM object for use in the GIS server, there are<br />

some specific guidelines you need to follow to ensure that you can use your object<br />

in a server context and that it will perform well in that environment. The guidelines<br />

below apply specifically to COM objects you create to run within the server.<br />

• You must explicitly create an interface that your COM class implements.<br />

Unlike Visual Basic 6, .NET will not create an implicit interface for your<br />

COM class that you can use when creating the object in a server context.<br />

• Your COM class should be marshalled using the Automation marshaller. You<br />

specify this by adding AutomationProxyAttribute to your class with a value of<br />

true.<br />

• Your COM class should generate a dual class interface. You specify this by<br />

adding ClassInterfaceAttribute to your class with a value of<br />

ClassInterfaceType.AutoDual.<br />

• To ensure that your COM object performs well in the server, it must inherit<br />

from ServicedComponent, which is in the System.EnterpriseServices assembly.<br />

This is necessary due to the current COM interop implementation of the<br />

.NET Framework.<br />

For more details and an example of a custom Server COM object written in<br />

.NET, see Chapter 4, ‘Developing <strong>ArcGIS</strong> Server applications’, in the <strong>ArcGIS</strong><br />

Server Administrator and <strong>Developer</strong> <strong>Guide</strong>.<br />

Releasing COM references<br />

<strong>ArcGIS</strong> <strong>Engine</strong> and <strong>ArcGIS</strong> Desktop applications<br />

An unexpected crash may occur when a standalone application attempts to shut<br />

down. For example, an application hosting a MapControl with a loaded map<br />

document will crash on exit. The crashes result from COM objects hanging<br />

around longer than expected. To avoid crashes, all COM references must be<br />

unloaded prior to shutdown. To help unload COM references, a static Shutdown<br />

function has been added to the ESRI.<strong>ArcGIS</strong>.Utility assembly. The following<br />

code excerpt shows the function in use.<br />

[VB.NET]<br />

Private Sub Form1_Closing(ByVal sender As Object, ByVal e As<br />

System.ComponentModel.CancelEventArgs) Handles MyBase.Closing<br />

ESRI.<strong>ArcGIS</strong>.Utility.COMSupport.AOUninitialize.Shutdown()<br />

End Sub<br />

[C#]<br />

private void Form1_Closing(object sender, CancelEventArgs e)<br />

{<br />

ESRI.<strong>ArcGIS</strong>.Utility.COMSupport.AOUninitialize.Shutdown();<br />

}<br />

The AOUninitialize.Shutdown function handles most of the shutdown problems in<br />

standalone applications, but you may still experience problems as there are COM<br />

objects that require explicit releasing; in these cases, call<br />

Chapter 4 • <strong>Developer</strong> environments • 175

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!