This is the third post regarding the Feature History Administrator plug-in. In the previous two posts you could learn how to create a new DocumentAdminPage from scratch and then how to extend it with some logic. And as I have already mentioned, I was not happy how it has been implemented :-)
One important thing for a good user experience is when a process takes more than a few seconds the application has to inform the user about the progress. See also here for some background information about that. Showing the progress of a function has several benefits:
- the user sees that the software is still working (!),
- it shows where the process roughly is and
- it can also give a hint when the process will be finished.
So let's add a progress form to the Analyze() method. The class we can use is the StatusForm and it is located in the Topobase.Data.Util namespace. (There is also a ConsoleStatusDisplay which can be used when you have is a console application). The StatusForm can either act as an infinite progress bar, if you have no idea how long the process takes, or a 0% to 100% progress bar.
The StatusForm consumes a background job, so let's first create one:
BackgroundJob<IList<FeatureClass>> job =
controller.Analyze;
StatusForm<IList<FeatureClass>> form =
new StatusForm<IList<FeatureClass>>(job);
The Analyze() method has to look like this: the first parameter is the StatusDisplay (to update the progress bar) followed by list of objects:
public void Analyze(IStatusDisplay statusDisplay,
params IList<FeatureClass>[] parameters)
The StatusForm and its background job can be cancelable. In our plug-in we would like to let the user be able to cancel the process, so let's set the right property:
form.CancelButtonEnabled = true;
We have to let the background job know which feature classes it has to analyze. Since it can't access the other properties from this class (cross-thread) we have to pass such information to the background job. Therefore we need to define it accordingly when we instantiate the StatusForm. In our example we need a list of Feature classes (StatusForm<IList<FeatureClass>>).
// pass the list of selected feature classes
// to the background job.
form.SetParameters(this.SelectedFeatureClasses);
// show the progress form,
// this method starts the background job
form.ShowDialog(this);
After calling the ShowDialog method the background job is started in a new thread. The GUI thread is now paused until the background job has finished.
If you take a look at the updated sample you will notice that I moved the Analyze() method to a new class called Controller. This is not necessary for the StatusForm, but I thought it would make sense to extract the logic from the UI and also improve the overall readability. Like the previous DocumentAdminPage samples this one is also written in C# and compatible with the official Topobase 2010 version.
Feel free to contact me for any questions or comments about this sample.
AUTODESK DOES NOT GUARANTEE THAT YOU WILL BE ABLE TO SUCCESSFULLY DOWNLOAD OR IMPLEMENT ANY SAMPLE CODE. SAMPLE CODE IS SUBJECT TO CHANGE WITHOUT NOTICE TO YOU. AUTODESK PROVIDES SAMPLE CODE "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL AUTODESK OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF DATA, OR LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, THAT MAY OCCUR AS A RESULT OF IMPLEMENTING OR USING ANY SAMPLE CODE, EVEN IF AUTODESK OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Comments