Working with the GeoprocessingResourceManager control


In this topic


Initializing a geoprocessing resource programmatically

A geoprocessing resource initializes when working with a GeoprocessingTask control. However, if you are working with a geoprocessing resource outside of the GeoprocessingTask, you might need to initialize it before it can be used. The same situation applies when creating a GeoprocessingResourceManager and adding geoprocessing resources dynamically at runtime. Specifically, the GeoprocessingResource needs to be initialized. The resource manager is responsible for managing the data source connection; therefore, if you are using an ArcGIS Server Local data source, server context creation and disposal are managed for you.
See the following code example that shows the GeoprocessingResource being initialized:
[C#]
GeoprocessingResourceManager geoprocessingResourceManager = new
    GeoprocessingResourceManager();
GeoprocessingResourceItem geoprocessingResourceItem = new GeoprocessingResourceItem()
    ;
geoprocessingResourceItem.Name = "GeoprocessingResourceItem";

GISResourceItemDefinition definition = new GISResourceItemDefinition();
definition.DataSourceDefinition = "http://localhost/arcgis/services";
definition.DataSourceType = "ArcGIS Server Internet";
definition.ResourceDefinition = "BufferTools";

geoprocessingResourceItem.Definition = definition;
geoprocessingResourceManager.ResourceItems.Add(geoprocessingResourceItem);
geoprocessingResourceManager.CreateResource(geoprocessingResourceItem);

IGISResource gisResource = geoprocessingResourceManager.GetResource(0);
if (!gisResource.Initialized)
    geoprocessingResourceItem.InitializeResource();