Application Hang after using DockablePane (Top level window is idle)

Application Hang after using DockablePane (Top level window is idle)

jw.vanasselt
Advocate Advocate
830 Views
12 Replies
Message 1 of 13

Application Hang after using DockablePane (Top level window is idle)

jw.vanasselt
Advocate
Advocate

Hi all,

One of the users has a problem with using a dockable pane application. (Library window)

The Dockable Pane is a WPF Page with xml data.

After MouseDoubleClick the an IExternalEventHandler Raise and in that event there a prompt to place a familysymbol.

 

Any ideas?

 

 

- <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
- <System>
  <Provider Name="Application Hang" /> 
  <EventID Qualifiers="0">1002</EventID> 
  <Version>0</Version> 
  <Level>2</Level> 
  <Task>101</Task> 
  <Opcode>0</Opcode> 
  <Keywords>0x80000000000000</Keywords> 
  <TimeCreated SystemTime="2024-03-14T11:14:34.1058526Z" /> 
  <EventRecordID>190754</EventRecordID> 
  <Correlation /> 
  <Execution ProcessID="0" ThreadID="0" /> 
  <Channel>Application</Channel> 
  <Computer>[ComputerName]</Computer> 
  <Security /> 
  </System>
- <EventData>
  <Data>Revit.exe</Data> 
  <Data>23.1.30.97</Data> 
  <Data>277c</Data> 
  <Data>01da75ffec5ff3c6</Data> 
  <Data>4294967295</Data> 
  <Data>C:\Program Files\Autodesk\Revit 2023\Revit.exe</Data> 
  <Data>cf05ffb2-a754-4417-b9c5-afa3235601e1</Data> 
  <Data /> 
  <Data /> 
  <Data>Top level window is idle</Data> 
  <Binary>54006F00700020006C006500760065006C002000770069006E0064006F0077002000690073002000690064006C00650000000000</Binary> 
  </EventData>
  </Event>

 

 This topic is a little bit related to this topic: 
Solved: Re: Close Dockable Window EventArgs - Autodesk Community - Revit Products

 

 

 

using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.UI;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Media;
using System.Xml;

namespace VDS
{
    class RevitPane : IDockablePaneProvider
    {
        // GUID voor DockablePane
        public static readonly Guid Id = new Guid("----");

        //Variable die toegewezen wordt in app
        public static RevitPane Default { get; private set; }

        public RevitPane(IExternalEventHandler_Bibliotheek eventHandler, ExternalEvent externalEvent)
        {
            EventHandler = eventHandler;
            ExternalEvent = externalEvent;
        }

        public IExternalEventHandler_Bibliotheek EventHandler { get; }
        public ExternalEvent ExternalEvent { get; }

        #region Registratie van panel positie
        public static void Register(UIControlledApplication app)
        {  
            

            var eventHandler = new IExternalEventHandler_Bibliotheek();
            var externalEvent = ExternalEvent.Create(eventHandler);

            Default = new RevitPane(eventHandler, externalEvent);

            var dockablePaneId = new DockablePaneId(Id);

            app.RegisterDockablePane(dockablePaneId, "Bibliotheek", Default);

           

        }

        

        #endregion

        #region Toggle panel aan/uit
        public static void Toggle(UIApplication app)
        {
            var dockablePaneId = new DockablePaneId(Id);
            var dockablePane = app.GetDockablePane(dockablePaneId);

            if (dockablePane.IsShown())
            {
                dockablePane.Hide();
            }
            else
            {
                dockablePane.Show();

                
            }

            
        }

        public void SetupDockablePane(DockablePaneProviderData data)
        {
            // wpf object with pane's interface
            data.FrameworkElement = new Viewer();
            // initial state position
            data.InitialState = new DockablePaneState
            {
                DockPosition = DockPosition.Right
            };            
        }

        
        #endregion
    }
}

 

 

Void that raised the event

 

private void LibraryListView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{

    List<FileData> selectedItemsList = new List<FileData>();

    foreach (var selectedItem in libraryListView.SelectedItems)
    {
        if (selectedItem is FileData fileData)
        {
            selectedItemsList.Add(fileData);
        }
    }


    RevitPane.Default.EventHandler.selectedFileData = selectedItemsList;
    RevitPane.Default.ExternalEvent.Raise();


}

 

 

0 Likes
831 Views
12 Replies
Replies (12)
Message 2 of 13

ricaun
Advisor
Advisor

Never heard about his Application Hang issue.

 

One thing that is not clear is what the IExternalEventHandler_Bibliotheek does, you mention something to place a family symbol?

 

Maybe a sample code to reproduce would help.

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 3 of 13

jw.vanasselt
Advocate
Advocate

Forgot that one to copy. 

 

using Autodesk.Revit.Attributes;
using Autodesk.Revit.Creation;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Events;
using Autodesk.Revit.DB.Structure;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Events;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Xaml;
using static VDS.VDS_standaard_definities;
using Document = Autodesk.Revit.DB.Document;

namespace VDS
{
    [Transaction(TransactionMode.Manual)]
    public class IExternalEventHandler_Bibliotheek : IExternalEventHandler
    {
        internal List<FileData> selectedFileData = new List<FileData>();
        //gegevens voor log
        private string fam_path = string.Empty;
        private string famtype = string.Empty;
        private string versienummer = string.Empty;

        public void Execute(UIApplication uiapp)
        {
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Document doc = uidoc.Document;
            FamilySymbol fs = null;
            Autodesk.Revit.ApplicationServices.Application app = doc.Application;
            versienummer = app.VersionNumber;


            using (Transaction trans = new Transaction(doc, "Family inladen"))
            {
                

                try
                {
                    trans.Start();
                                        
                    // Filedatas doorlopen
                    foreach (FileData file in selectedFileData)
                    {
                        
                        //FamilyPath en type bepalen
                        string familyPath = file.FamilyPath;
                        string familyTypeName = file.FamilyTypeName;
                        string familyName= GetFileNameWithoutExtension(familyPath);

                        fam_path = familyPath;
                        famtype = familyTypeName;

                        // FamilySymbol ophalen vanuit familyName en familytype name
                        fs = new FilteredElementCollector(doc)
                            .OfClass(typeof(FamilySymbol))
                            .Cast<FamilySymbol>()
                            .FirstOrDefault(x => x.FamilyName == familyName && x.Name == familyTypeName);


                        // Als niet aanwezig is dan inladen
                        if (fs == null)
                        {
                            CustomFamilyLoadOptions load_options = new CustomFamilyLoadOptions();

                            if(doc.LoadFamilySymbol(familyPath, familyTypeName, load_options, out fs))
                            {
                                continue;
                            }
                            else
                            {
                                TaskDialog.Show("Error", "Er gaat iets mis met het inladen van de family.");
                            }
                            

                            
                        }                        
                    }


                    trans.Commit();
                }
                catch (Exception ex)
                {
                    TaskDialog.Show("Waarschuwing", $"{ex.Message}\n\n{ex.StackTrace}");
                    trans.Commit();
                }
                
            }
                        
            // Event trigger aanmaken voor plaatsen component
            app.DocumentChanged += new EventHandler<DocumentChangedEventArgs>(OnDocumentChanged);

            // Family plaatsen en aan de muis hangen
            try
            {
                // Plaatsen familys
                uidoc.PromptForFamilyInstancePlacement(fs);
            }
            catch 
            {
                
            }

            // Event trigger sluiten voor performance
            app.DocumentChanged -= new EventHandler<DocumentChangedEventArgs>(OnDocumentChanged);

            //leegmaken van gegevens
            fam_path = string.Empty;
            famtype = string.Empty;


        }
        void OnDocumentChanged(object sender, DocumentChangedEventArgs e)
        {
            
            if (e.GetTransactionNames().Contains("Component"))
            {
                // Bibliotheek log vullen
                VDS_Log vDS_Log = new VDS_Log();
                vDS_Log.Bibliotheek_log(fam_path, famtype, versienummer);
            }
            
        }

        static string GetFileNameWithoutExtension(string path)
        {
            // Gebruik de Path-klasse om het bestandsnaamcomponent uit het pad te halen
            string fileName = Path.GetFileName(path);

            // Vervolgens haal je de extensie eraf
            string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);

            // Split het pad op de backslash ('\') en neem het laatste deel
            string[] pathParts = path.Split('\\');
            string lastPart = pathParts[pathParts.Length - 1];

            // Verwijder het laatste deel uit de bestandsnaam
            fileNameWithoutExtension = fileNameWithoutExtension.Replace(lastPart, "");

            return fileNameWithoutExtension.Trim('\\');
        }

        public string GetName()
        {
            return "Bibliotheek eventhandler";
        }
    }
}
0 Likes
Message 4 of 13

jw.vanasselt
Advocate
Advocate

I see that I use the Commit() inside the catch, should that be the problem?

0 Likes
Message 5 of 13

ricaun
Advisor
Advisor

The code looks right, I didn't spot anything strange.

 

The `Commit()` caught my eye, and looks fine, I usually put Rollback in there.

 

One thing I didn't get is, where that XML data for the error is coming from?

 

The 'Application hang' is like Revit freezes and eventually shows a fatal error like this?

Fatal Error - Revit 2021.PNG

 

And what else do you have inside the page `Viewer`, if some exceptions happen in some events in the WPF, the Revit application usually crashes.

 

A button with this click event gonna make Revit unhappy.

private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
    throw new Exception("Fatal Error!");
}

 

 

 

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 6 of 13

jw.vanasselt
Advocate
Advocate

 No, there is no crash,  the Application hang after using the tool, after 2/3 minutes you can use revit again. When I use the library again the Application is hanging again.

 

The viewer is reading xml data and views products with a image and product data

 

There is a search option in it

0 Likes
Message 7 of 13

ricaun
Advisor
Advisor

Now I get it what the Application hang means, your code is doing a big process and Revit is not responding until the process ends.

 

How big is the selectedFileData list?

 

If you selectedFileData is big and you have many symbols in the document, pretty sure your code is waiting time checking if the symbol exist in the document.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 8 of 13

jw.vanasselt
Advocate
Advocate

The selectedFileData is a single (binding) element with a path to the place where the family is located and the specific type. After that I check if the family is loaded, of he isnt i load it into the project. Otherwise I use the one in the project 

0 Likes
Message 9 of 13

jw.vanasselt
Advocate
Advocate

Any suggestions how to log/debug to find the problem?

0 Likes
Message 10 of 13

ricaun
Advisor
Advisor

If it is a single file why `selectedFileData` is a list?

 

I suppose the FilteredElementCollector could be running multiple times that, but it could be other stuff.

 

The best way to debug is to create some IExternalCommand and test it there.

 

Luiz Henrique Cassettari

ricaun.com - Revit API Developer

AppLoader EasyConduit WireInConduit ConduitMaterial CircuitName ElectricalUtils

0 Likes
Message 11 of 13

jw.vanasselt
Advocate
Advocate

Good question, I guess it's not necessary.
I will review my code Log everything to see what is going wrong.

0 Likes
Message 12 of 13

ctm_mka
Collaborator
Collaborator

Curious about the use of "MouseButtonEventArgs". The event handler does not seem to specifically be looking for a double click, perhaps it is firing twice, thus the hang?

0 Likes
Message 13 of 13

jw.vanasselt
Advocate
Advocate

The handler is Raising the EventHandler.

0 Likes