private void SearchForTopBlocks(string blkName, int targetCount) { List <ObjectId> blkIds = new List <ObjectId>(); try { if (ProcessingStarted != null) { string msg = string.Format( "Searching first {0} block refeences: \"{1}\"", targetCount, blkName); LongProcessStartedEventArgs e = new LongProcessStartedEventArgs(msg); ProcessingStarted(this, e); } using (var tran = _dwg.TransactionManager.StartTransaction()) { //Get all entities' ID in ModelSpace BlockTableRecord model = (BlockTableRecord)tran.GetObject( SymbolUtilityServices.GetBlockModelSpaceId( _dwg.Database), OpenMode.ForRead); foreach (ObjectId id in model) { if (ProcessingProgressed != null) { string progMsg = string.Format( "{0} found\n" + "Processing entity: {1}", blkIds.Count, id.ObjectClass.DxfName); LongProcessingProgressEventArgs e = new LongProcessingProgressEventArgs(progMsg); ProcessingProgressed(this, e); } if (IsTargetBlock(id, blkName, tran)) { blkIds.Add(id); if (blkIds.Count == targetCount) { break; } } } tran.Commit(); } ProcessingEnded?.Invoke(this, EventArgs.Empty); } finally { //Make sure the CloseProgressUIRequested event always fires, //so that the progress dialog box gets closed because of //this event CloseProgressUIRequested?.Invoke(this, EventArgs.Empty); } }
private void ExecutingObject_Progressed( object sender, LongProcessingProgressEventArgs e) { if (!_isMarquee) { pBar.Value++; } lblDescription.Text = e.ProgressDescription; lblDescription.Refresh(); Application.DoEvents(); if (_stop) { e.Cancel = true; } }
private void LoopThroughModelSpace() { try { //run 2 long processing loops for (int n = 0; n < 2; n++) { using (var tran = _dwg.TransactionManager.StartTransaction()) { //Get all entities' ID in ModelSpace BlockTableRecord model = (BlockTableRecord) tran.GetObject( SymbolUtilityServices.GetBlockModelSpaceId( _dwg.Database), OpenMode.ForRead); ObjectId[] entIds = model.Cast <ObjectId>().ToArray(); if (ProcessingStarted != null) { string process = n == 0 ? "Searching ModelSpace for AAAA" : "Search ModelSpace for BBBB"; LongProcessStartedEventArgs e = new LongProcessStartedEventArgs( process, entIds.Length, true); ProcessingStarted(this, e); } int count = 0; foreach (var entId in entIds) { count++; if (ProcessingProgressed != null) { string progMsg = string.Format( "{0} out of {1}. {2} remaining...\n" + "Processing entity: {3}", count, entIds.Length, entIds.Length - count, entId.ObjectClass.DxfName); LongProcessingProgressEventArgs e = new LongProcessingProgressEventArgs(progMsg); ProcessingProgressed(this, e); //Since this processing is cancellable, we //test if user clicked the "Stop" button in the //progressing dialog box if (e.Cancel) { break; } } //Do something with the entity Entity ent = (Entity)tran.GetObject( entId, OpenMode.ForRead); long s = 0; for (int i = 0; i < 1000000; i++) { s += i * i; } } ProcessingEnded?.Invoke(this, EventArgs.Empty); tran.Commit(); } } } finally { //Make sure the CloseProgressUIRequested event always fires, so //that the progress dialog box gets closed because of this event CloseProgressUIRequested?.Invoke(this, EventArgs.Empty); } }