Note that there are some explanatory texts on larger screens.

plurals
  1. POThreading and ArcGIS
    text
    copied!<p>I have just stumbled across the Backgroundworker object, and it seems like the tool I'm looking for to make my GUI responding while performing calculations. I am writing IO plugins for ArcGIS.</p> <p>I am doing some data processing outside ArcGIS, which works fine using the backgroundworker. But when I'm inserting the data into ArcGIS, the backgroundworker seems to increase the duration time by a factor 9 or so. Placing the processing code outside the DoWork method, increases the performance by a factor 9.</p> <p>I have read about this several places on the net, but I have no experience in multithreaded programming and the terms like STA and MTA means nothing to me. <a href="http://edndoc.esri.com/arcobjects/9.2/NET/2c2d2655-a208-4902-bf4d-b37a1de120de.htm" rel="nofollow noreferrer">link text</a> I have also tried to use a simple implementation of threading, but with similar results.</p> <p>Does anyone know what I can do to be able to use ArcGIS processing and maintaining a responsive GUI?</p> <p>EDIT: I have included a sample of my interaction with the background worker. If I put the code located in the StartImporting method in the cmdStart_Click method, it executes much faster.</p> <pre><code>private void StartImporting(object sender, DoWorkEventArgs e) { DateTime BeginTime = DateTime.Now; // Create a new report object. SKLoggingObject loggingObject = new SKLoggingObject("log.txt"); loggingObject.Start("Testing."); SKImport skImporter = new SKImport(loggingObject); try { // Read from a text box - no writing. skImporter.Open(txtInputFile.Text); } catch { } SKGeometryCollection convertedCollection = null; // Create a converter object. GEN_SK2ArcGIS converter = new GEN_SK2ArcGIS(loggingObject); // Convert the data. convertedCollection = converter.Convert(skImporter.GetGeometry()); // Create a new exporter. ArcGISExport arcgisExporter = new ArcGISExport(loggingObject); // Open the file. // Read from a text box - no writing. arcgisExporter.Open(txtOutputFile.Text); // Insert the geometry collection. try { arcgisExporter.Insert(convertedCollection); } catch { } TimeSpan totalTime = DateTime.Now - BeginTime; lblStatus.Text = "Done..."; } private void ChangeProgress(object sender, ProgressChangedEventArgs e) { // If any message was passed, display it. if (e.UserState != null &amp;&amp; !((string)e.UserState).Equals("")) { lblStatus.Text = (string)e.UserState; } // Update the progress bar. pgStatus.Value = e.ProgressPercentage; } private void ImportDone(object sender, RunWorkerCompletedEventArgs e) { // If the process was cancelled, note this. if (e.Cancelled) { pgStatus.Value = 0; lblStatus.Text = "Operation was aborted by user..."; } else { } } private void cmdStart_Click(object sender, EventArgs e) { // Begin importing the sk file to the geometry collection. // Initialise worker. bgWorker = new BackgroundWorker(); bgWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(ImportDone); bgWorker.ProgressChanged += new ProgressChangedEventHandler(ChangeProgress); bgWorker.DoWork += new DoWorkEventHandler(StartImporting); bgWorker.WorkerReportsProgress = true; bgWorker.WorkerSupportsCancellation = true; // Start worker. bgWorker.RunWorkerAsync(); } private void cmdCancel_Click(object sender, EventArgs e) { bgWorker.CancelAsync(); } </code></pre> <p>Kind Regards, Casper</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload