@@ -147,22 +147,17 @@ A handler that provides access to modify a Revit document outside the execution
147147Calling a handler in a Revit context will call it immediately, without adding it to the queue.
148148
149149``` c#
150- public ViewModel
151- {
152- ActionEventHandler = new ActionEventHandler ();
153- }
154-
155- public ActionEventHandler ActionEventHandler { get ; }
156- public ElementId ElementId { get ; set ; }
150+ private readonly ElementId _elementId = new (12869 );
151+ private readonly ActionEventHandler _actionEventHandler = new ();
157152
158153private void DeteleElement ()
159154{
160- ActionEventHandler .Raise (application =>
155+ _actionEventHandler .Raise (application =>
161156 {
162157 var document = application .ActiveUIDocument .Document ;
163158 using var transaction = new Transaction (document , $" Delete element" );
164159 transaction .Start ();
165- document .Delete (ElementId )
160+ document .Delete (_elementId )
166161 transaction .Commit ();
167162
168163 Debug .WriteLine (" Deleted" );
@@ -194,16 +189,11 @@ Suitable for cases where you need to call code when Revit receives focus.
194189For example, to display a window after loading a family into a project.
195190
196191``` c#
197- public ViewModel
198- {
199- IdlingEventHandler = new IdlingEventHandler ();
200- }
201-
202- public IdlingEventHandler IdlingEventHandler { get ; }
192+ private readonly IdlingEventHandler _idlingEventHandler = new ();
203193
204194private void NotifyOnIdling ()
205195{
206- IdlingEventHandler .Raise (application =>
196+ _idlingEventHandler .Raise (application =>
207197 {
208198 var view = new FamilyBrowser ();
209199 view .Show ();
@@ -234,16 +224,11 @@ Calling the handler in a Revit context will call it immediately without adding i
234224and you can still call API requests in the main Revit thread.
235225
236226``` c#
237- public ViewModel
238- {
239- AsyncEventHandler = new AsyncEventHandler ();
240- }
241-
242- public AsyncEventHandler AsyncEventHandler { get ; }
227+ private readonly AsyncEventHandler _asyncEventHandler = new ();
243228
244229private async Task DeleteDoorsAsync ()
245230{
246- await AsyncEventHandler .RaiseAsync (application =>
231+ await _asyncEventHandler .RaiseAsync (application =>
247232 {
248233 var doorIds = document .GetInstanceIds (BuiltInCategory .OST_Doors );
249234 document .Delete (doorIds );
@@ -274,16 +259,11 @@ Calling the handler in a Revit context will call it immediately without adding i
274259and you can still call API requests in the main Revit thread.
275260
276261``` c#
277- public ViewModel
278- {
279- AsyncEventHandler = new AsyncEventHandler <int >();
280- }
281-
282- public AsyncEventHandler < int > AsyncEventHandler { get ; }
262+ private readonly AsyncEventHandler < int > _asyncEventHandler = new ();
283263
284264private async Task GetWindowsCountAsync ()
285265{
286- var windowsCount = await AsyncEventHandler .RaiseAsync (application =>
266+ var windowsCount = await _asyncEventHandler .RaiseAsync (application =>
287267 {
288268 var uiDocument = application .ActiveUIDocument ;
289269 var elementIds = uiDocument .Document .GetInstanceIds (BuiltInCategory .OST_Windows );
0 commit comments