2017-08-08 221 views
-1

我想重複以下Autodesk例子: http://help.autodesk.com/view/RVT/2016/ENU/?guid=GUID-CEF0F9C9-046E-46E2-9535-3B9620D8A170的Revit:TaskDialog其實裏面事件處理

我得到的Revit的完整崩潰時,我開始加載項。在調試模式下,visual studio指向這一行:「TaskDialogResult result = taskDialog.Show();」 - 類型 'System.StackOverflowException' 未處理的異常發生在RevitAPIUI.dll

public class Application_DialogBoxShowing : 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 help id of the showing dialog 
       int dialogId = args.HelpId; 

       // Format the prompt information string 
       String promptInfo = "A Revit dialog will be opened.\n"; 
       promptInfo += "The help id of this dialog is " + dialogId.ToString() + "\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.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); 
       } 
     } 
} 

回答

0

使用 「消息框」,而不是 「TaskDialog其實」。 在AppDialogShowing中調用「TaskDialog」會導致溢出。