private void RunTool(Geoprocessor geoprocessor, IGPProcess process, ITrackCancel TC) { geoprocessor.OverwriteOutput = true; try { geoprocessor.Execute(process, null); ReturnMessage(geoprocessor); } catch(Exception err){ MessageBox.Show(err.Message); ReturnMessage(geoprocessor); } } private void ReturnMessage(Geoprocessor gp) { string ms = ""; if (gp.MessageCount > 0) { for (int count = 0; count <= gp.MessageCount - 1; count++) ms += gp.GetMessage(count)+" "; } }
RunTool(gp, pViewshed, null);
用这个函数就可以查出GP调用是哪里出错了。