using System;
using System.Threading;
using System.Windows;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
namespace KRDimensions
{
[Transaction(TransactionMode.Manual)]
public class Test : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
ProgressWindow progressWindow = new ProgressWindow();
progressWindow.Show();
try
{
// long process with progress window
for (int i = 0; i < 10; i++)
{
Thread.Sleep(500);
progressWindow.Dispatcher.Invoke(() => progressWindow.TbProgressText.Text = "progress: " + i);
if(StopProcess)
break;
}
}
catch (Exception exception)
{
MessageBox.Show(exception.Message);
}
progressWindow.Dispatcher.Invoke(() => { progressWindow.Close(); });
return Result.Succeeded;
}
public static bool StopProcess { get; set; } = false;
}
}