Bug in the revit documentation for DialogBoxShowing Event

Bug in the revit documentation for DialogBoxShowing Event

Anonymous
Not applicable
708 Views
2 Replies
Message 1 of 3

Bug in the revit documentation for DialogBoxShowing Event

Anonymous
Not applicable

Here is the link

Will the call to show the TaskDialog from within an event handler that handles the DialogShow event not create an infinite loop?

I am getting a stack overflow exception. If I remove the TaskDialog show below, it works fine. 

0 Likes
709 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk

Dear Jeetendra,

 

Thank you for your report.

 

Maybe the sample code in the documentation worked once upon a time and has not been updated.

 

Can you please provide a minimal reproducible case that I can pass on to the development team for analysis?

 

http://thebuildingcoder.typepad.com/blog/about-the-author.html#1b

 

Thank you!

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 3

Anonymous
Not applicable

 

public class Class1 : IExternalApplication
    {
        // Implement the OnStartup method to register events when Revit starts.
    public Result OnStartup(UIControlledApplication application)
    {
        // Register related events
        application.DialogBoxShowing += 
            new EventHandler<Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs>(AppDialogShowing);
        return Result.Succeeded;
    }

    // Implement this method to unregister the subscribed events when Revit exits.
    public Result OnShutdown(UIControlledApplication application)
    {
        // unregister events
        application.DialogBoxShowing -= 
            new EventHandler<Autodesk.Revit.UI.Events.DialogBoxShowingEventArgs>(AppDialogShowing);
        return Result.Succeeded;
    }

    // The DialogBoxShowing event handler, which allow you to 
    // do some work before the dialog shows
    void AppDialogShowing(object sender, DialogBoxShowingEventArgs args)
    {
        // Get the string id of the showing dialog
        String dialogId = args.DialogId;

        // Format the prompt information string
        String promptInfo = "A Revit dialog will be opened.\n";
        promptInfo += "The DialogId of this dialog is " + dialogId + "\n";
        promptInfo += "If you don't want the dialog to open, please press cancel button";

        // Show the prompt message, and allow the user to close the dialog directly.
        TaskDialog taskDialog = new TaskDialog("Revit");
        taskDialog.Id = "Customer DialogId";
        taskDialog.MainContent = promptInfo;
        TaskDialogCommonButtons buttons = TaskDialogCommonButtons.Ok | 
                                            TaskDialogCommonButtons.Cancel;
        taskDialog.CommonButtons = buttons;
        TaskDialogResult result = taskDialog.Show();
        if (TaskDialogResult.Cancel == result)
        {
            // Do not show the Revit dialog
            args.OverrideResult(1);
        }
        else
        {
            // Continue to show the Revit dialog
            args.OverrideResult(0);
        }
    }
    }

Here is the minimal reproducible case. 

 

0 Likes