ricaun.Revit.UI.Tasks
1.0.0
Prefix Reserved
dotnet add package ricaun.Revit.UI.Tasks --version 1.0.0
NuGet\Install-Package ricaun.Revit.UI.Tasks -Version 1.0.0
<PackageReference Include="ricaun.Revit.UI.Tasks" Version="1.0.0" />
paket add ricaun.Revit.UI.Tasks --version 1.0.0
#r "nuget: ricaun.Revit.UI.Tasks, 1.0.0"
// Install ricaun.Revit.UI.Tasks as a Cake Addin #addin nuget:?package=ricaun.Revit.UI.Tasks&version=1.0.0 // Install ricaun.Revit.UI.Tasks as a Cake Tool #tool nuget:?package=ricaun.Revit.UI.Tasks&version=1.0.0
ricaun.Revit.UI.Tasks
ricaun.Revit.UI.Tasks
package allows using Task
to run Revit API code asynchronously and await
the code to finish.
This project was generated by the ricaun.AppLoader Revit plugin.
Features
- Task: Run
Revit API
code asynchronously andawait
the code to finish. - InContext: Run code if in
Revit Context
instead of awaitingTask
. - CancellationToken: Provides support for canceling asynchronous tasks.
RevitTaskService
The RevitTaskService
is a service that manages the creation of the AsyncExternalEventHandler
inside the Idling
event.
UIApplication uiapp;
RevitTaskService revitTaskService = new RevitTaskService(uiapp);
or
UIControlledApplication application;
RevitTaskService revitTaskService = new RevitTaskService(application);
Initialize
Initialize the RevitTaskService
to start the Idling
event.
revitTaskService.Initialize();
Dispose
Dispose the RevitTaskService
to stop the Idling
event.
revitTaskService.Dispose();
IRevitTask
The RevitTaskService
has the interface IRevitTask
with the Run
method to execute code in Revit Context.
IRevitTask revitTask = revitTaskService;
Run
The Run
method runs the code inside Revit Context and await
the code to finish with a CancellationToken
.
CancellationToken token = CancellationToken.None;
UIApplication uiapp = await revitTask.Run((uiapp) =>
{
// Code run inside Revit Context
return uiapp;
}, token);
The IRevitTask
interface has an extension methods for Run
without UIApplication
or CancellationToken
and return
.
await revitTask.Run(() => { });
await revitTask.Run(() => { return 1; });
await revitTask.Run((uiapp) => { });
await revitTask.Run((uiapp) => { return 1; });
await revitTask.Run(() => { }, token);
await revitTask.Run(() => { return 1; }, token);
await revitTask.Run((uiapp) => { }, token);
Example
Example sample to implement RevitTaskService
within IExternalApplication
.
public class App : IExternalApplication
{
private static RevitTaskService revitTaskService;
public static IRevitTask RevitTask => revitTaskService;
public Result OnStartup(UIControlledApplication application)
{
revitTaskService = new RevitTaskService(application);
revitTaskService.Initialize();
Task.Run(async () =>
{
await Task.Delay(1000);
await RevitTask.Run(() =>
{
TaskDialog.Show("Revit", "Hello from RevitTask");
});
});
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
revitTaskService?.Dispose();
return Result.Succeeded;
}
}
Similar Projects
There are some similar packages/implementations to run Revit API code in an async way using await/Tasks.
Release
License
This project is licensed under the MIT Licence.
Do you like this project? Please star this project on GitHub!
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0-windows7.0 is compatible. |
.NET Framework | net46 is compatible. net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
-
.NETFramework 4.6
- No dependencies.
-
net8.0-windows7.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 979 | 3/5/2024 |