0

I'm working on a Revit plugin that displays a WPF window to manipulate some collected data and send it back to the Revit command to do the logic. I'm trying to use a MVVM approach so in the command which is the entry point, I'm following this logic:

  1. Collect the data into 2 lists of the model.
  2. Instantiate the parameterized view model with the 2 lists.
  3. Instantiate the window with the view model then ShowDialog() it.
  4. Manipulate the data.
  5. Terminate the window and get its dialog result.
  6. Grab back the manipulated data from the view model instance and process it.
  7. commit changes to the Revit model.

Everything seems to work fine but the problem is that data collection of the second list can take some time if the model is big and the user gets the spinner for a while before the window shows up, which gives the impression that Revit have frozen.

I then tried to instantiate the model view with an empty list2 to show the window early and maybe implement a progress bar using these steps:

  1. Collect List 1
  2. instantiate VM with List 1 and an emplty List 2
  3. Display window
  4. Collect list 2
  5. Change the List2 property in the VM instance
  6. Resume the same logic above...

But the widow is showing with only list1 being populated. I'm suspecting that the applications gets stuck after displaying the WPF window and the command is never continued but I'm not sure how to debug that. Should I be using threading to display the window? in case yes, how do I do that?

Samer
  • 11
  • 1
  • 6
  • You're right to think about moving the slow process to another thread. The usual way to do that is with Async and Await - https://stackoverflow.com/questions/14455293/how-and-when-to-use-async-and-await – Robin Bennett Nov 29 '18 at 11:42
  • If you are using MVVM you need to be binding the lists correctly. Additionally List 2 needs to be updated (PropertyChanged event) to inform the window. With correct binding setup and posting the event you should be able to display List 2 after it has been collected. If you provide some code it gets more easy to understand your problem. – plori Nov 29 '18 at 14:01

0 Answers0