You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects 3rd Party IDE (C++, VB, C#, Delphi, etc.) forum

Blocking my C# program until the ArcMap Aut...   Steven Citron-Pousty Aug 02, 2006
Re: Blocking my C# program until the ArcMap...   Neil Clemmons Aug 02, 2006
Re: Blocking my C# program until the ArcMap...   Steven Citron-Pousty Aug 02, 2006
Re: Blocking my C# program until the ArcMap...   Neil Clemmons Aug 02, 2006
Re: Blocking my C# program until the ArcMap...   Steven Citron-Pousty Aug 02, 2006
Re: Blocking my C# program until the ArcMap...   Neil Clemmons Aug 02, 2006
Re: Blocking my C# program until the ArcMap...   Steven Citron-Pousty Aug 02, 2006
Re: Blocking my C# program until the ArcMap...   stephanie li Jan 25, 2007
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Blocking my C# program until the ArcMap Automation is finished 
Author Steven Citron-Pousty 
Date Aug 02, 2006 
Message I modified the automation sample to open ArcMap and then load a document (MXD). After the document is loaded I make some calls to the document. My problem is that for larger or slow loading MXDs, my C# code keeps going before the document is fully loaded. I know this is because my code and ArcMap are in seperate threads.

How do I block my code until the document is loaded? All I need is an example or a web page to reference. I am new to C# and Automation but I have a long history in Java and I am proficient in ArcObjects.

Thanks in advance for your help... 
 
//Start arcmap
ArcMapDoc = new MxDocumentClass();
//Get a reference to the application
ArcMapApp = ArcMapDoc.Parent;
//I don't think I need to Show arcmap
ArcMapApp.Visible = true;
ArcMapApp.OpenDocument(file);  

//I NEED SOMETHING TO WAIT HERE UNTIL THE DOCUMENT IS LOADED
//OR I NEED TO PUT THE SUBSEQUENT CODE IN A CONSTRUCT THAT KNOW TO WAIT FOR THE DOCUMENT OPENED  EVENT FROM ARCMAP

ESRI.ArcGIS.Geodatabase.IEnumDataset datasets = ArcMapDoc.Datasets;
ESRI.ArcGIS.Geodatabase.IDataset dataset = datasets.Next();
 
  Steven Citron-Pousty

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Blocking my C# program until the ArcMap Automation is finished 
Author Neil Clemmons 
Date Aug 02, 2006 
Message You might try calling the Sleep method. It's in the .NET documentation if you don't already know how to use it. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Blocking my C# program until the ArcMap Automation is finished 
Author Steven Citron-Pousty 
Date Aug 02, 2006 
Message I thought about that but I am not sure how long I should sleep for. I guess I could pick some arbitrary amount like 3 minutes but that would be wasteful on small map documents. Do you other ideas about how this might work?
By the way, thanks for answering so quickly... 
  Steven Citron-Pousty

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Blocking my C# program until the ArcMap Automation is finished 
Author Neil Clemmons 
Date Aug 02, 2006 
Message I usually recommend against using "automation". It's not really automation and is prone to a lot of errors and problems. What exactly are you doing? There may be alternatives. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Blocking my C# program until the ArcMap Automation is finished 
Author Steven Citron-Pousty 
Date Aug 02, 2006 
Message Here is what I am trying to do
http://thesteve0.wordpress.com/2006/08/01/mr-mxd-tell-me-all-your-datasources/

The only way to get to the IDocumentDatasets interface is through an MXDocument. And the only handle I can find to an MxDocument is through ArcMap directly. There is a longer way to do the same problem but this way seems much more straightforward. I bet if I had an MapControl in Engine I could get the same information, but I do not have access to engine.

I do not want to go the long route of looping through layers because I also want to get a list of the tables. 
  Steven Citron-Pousty

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Blocking my C# program until the ArcMap Automation is finished 
Author Neil Clemmons 
Date Aug 02, 2006 
Message You can do this using the IMapDocument interface. This eliminates the need to actually start an instance of ArcMap and will keep all of your code running in the same process. You won't be able to use IDocumentDatasets, but you can build the same functionality by looping through the layers in the map. You just have to handle the possibility that you could run into the same dataset more than once. 
  Neil Clemmons
Senior GIS Developer
Geographic Information Services, Inc.
Birmingham, AL
http://www.gis-services.com

Check out our blog:
http://blog.gis-services.com/ 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Blocking my C# program until the ArcMap Automation is finished 
Author Steven Citron-Pousty 
Date Aug 02, 2006 
Message I could handle the duplicate data with a hash. I don't want to write that looping for all the possible permutations including group layers. I have a hack to handle this which is to wait for the title to change from Untitled to anything else. I know this is a hack but then again so is using ArcMap through automation. It would be nice if MapDocument implemented the interface I want. I would suspect there would be a way to do this with some Engine controls but I don't have my EDN license =(.
I'll give you the points for helping out 
  Steven Citron-Pousty

 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: Blocking my C# program until the ArcMap Automation is finished 
Author stephanie li 
Date Jan 25, 2007 
Message Hi,
I am very interested in the ArcMap automation example you created, but I could not find them throught the link. May I take a look please?

Thanks,
Stephanie