IGPFunction2.Execute() never triggers when using IEnumLayer.Next()

419
1
Jump to solution
02-16-2013 02:22 AM
ØyvindIdland
New Contributor III
Hello,

I got an issue in a custom GP tool I don't really understand:

In my UpdateMessages() method, I use the following code to run through all layers:

IEnumLayer enumLayer = gpUtils.GetMapLayers(); enumLayer.Reset(); ILayer layer = enumLayer.Next(); while (layer != null) {     <code here>     layer = enumLayer.Next(); }


The purpose is to look for layers with duplicate names.

This works fine when I don't run the tool in the background. In background mode however, the Execute() method is never
triggered.

This seems to happen after enumLayer.Next(). When commenting away the enumLayer.Next() and the code below, it works again.

There are no error messages or exceptions occuring, and Arc claims that the tool executed succesfully.
When calling IGPMessages.AddMessage() as the first action in Exceute(), nothing is yielded.

Am I missing something here ?


Oyvind
0 Kudos
1 Solution

Accepted Solutions
ØyvindIdland
New Contributor III
I resolved this when attaching the debugger to the background process:

Turns out that right before Execute() is about to be called, UpdateMessages() is triggered.
In this case, the IGPUtilities.GetMapLayers() returns null and there fore an exception is thrown inside UpdateMessages().

ArcGis then announces happily that the tool succeeded in 2 seconds.

Workaround: check the return value from GetMapLayers().

View solution in original post

0 Kudos
1 Reply
ØyvindIdland
New Contributor III
I resolved this when attaching the debugger to the background process:

Turns out that right before Execute() is about to be called, UpdateMessages() is triggered.
In this case, the IGPUtilities.GetMapLayers() returns null and there fore an exception is thrown inside UpdateMessages().

ArcGis then announces happily that the tool succeeded in 2 seconds.

Workaround: check the return value from GetMapLayers().
0 Kudos