I was reading a thread from a few years ago that talked about an issue I am having now, I have a WPF application that has a long running process iterating files, I would prefer to run this process as a Task in a background thread, either by using backgroundworker or async, but it appears that Microsation does not allow you to load a DGN file from non-application thread.
Is there a way to update the UI and keep it responsive during this process? In VBA there's DoEvents, it doesn't release the UI but it does allow it to be refreshed/repainted. Any options on this?
Hi Victor,
Can you give a try to the following approach?
1. Create a new class inheriting Bentley.DgnPlatformNET.Host.
for e.g. internal class DgnHost : Bentley.DgnPlatformNET.Host
2. Inside your Task/Async method. Before using any DgnPlatform API, write the following.
// Initialize Host for DgnPlatform Bentley.DgnPlatformNET.Host session = new DgnHost (); Bentley.DgnPlatformNET.DgnPlatformLib.Initialize (session, false);
For UI
You need to update your UI on the main thread. Try to implement some mechanism to post progress from Task/Async method.
And on that UI update event, update your UI like:
System.Windows.Application.Current.Dispatcher.Invoke(() => {//code to update UI. });
Please give it a try!
Thanks,
Mangesh
Answer Verified By: Viktor_Kulik
Hmmm this is interesting, its not clear as to what's going on there, but it does appear to work beautifully. Thank you very much!