Solidworks' frozen UI

How do you keep the SolidWorks UI responsive after triggering methods in your code asynchronously?

Using Task.Run() is not advisable because you’re manipulating COM objects.

SolidWorks isn’t really built for doing things asynchronously, so I don’t use it. I only use Task.Run when refreshing a license, for example, so I can show a moving spinner in the UI.

Sometimes batch processing models is too slow for my liking, but you can turn off many solidworks features to make it faster.

What are you building, and what needs to be done asynchronously?

That’s the reason why I build my own UI’s with WPF or Blazor… but yes, with that you have then other problems :sweat_smile:

You can achieve some level of responsiveness by offloading progress reporting to Windows-native API controls. One useful library is ookii-dialogs/ookii-dialogs-wpf, which provides dialog controls that appear to run on a separate process, improving UI responsiveness during long operations.

You can copy paste the code from their repo. I am using something similar.

@PeterBrinkhuis ,

For example, set the ModelView::EnableGraphicsUpdate to false to speed up the API execution. Then, set it back to true at the end and save the model. In my application the model thumbnail is blank.

class Main
{
'Command bar custom button starts:'
new Example().Run();
}

class Example
{
  'Constructor'
  private Example()
  {
  'Set the global variables'
  }

  public void Run()
  {
  ModelView.EnableGraphicsUpdate = false;
  
  'Set a custom WPF dialog box for user information and block interaction with the SolidWorks UI until the dialog is closed'

  MyDialogBox.Show();

  'Do a lot of work here...'
  
  ModelView.EnableGraphicsUpdate = true;
  
  ModelDoc.Save3();
  }
}

Yes, that is what happens when you disable graphics. You need to call GraphicsRedraw before saving, or maybe a rebuild.