[C# MicroStation CE] Prevent entering modal state / close dialogs

Hi all,

I am currently building an application for processing dgn files using IPC (inter-process communication) method. Everything seems to be working quite nicely except for when a modal dialog is created that will block the current thread, preventing processing from continuing execution.

Has anyone found any methods for closing out modal dialogs when they are opened? Here's what I have tried so far:

//1: Application event watcher to detect when the active thread is in a modal state
Application.EnterThreadModal += Application_EnterThreadModal;
...

//2: Monitor open forms as backround task (since modal will block current thread)
private void Application_EnterThreadModal(object sender, EventArgs e)
{
    Task.Run(() => CheckForms()); //Run as background task
}

private static void CheckForms()
{
    Thread.Sleep(1000); //Delay to allow form to load

    System.Windows.Application.Current.Dispatcher.Invoke(() =>
    {
        //1: Fails - no entry point found in stdmdlbltin.dll?
        IntPtr current = MdlWrappers.mdlDialog_getFirst();
        while (current != IntPtr.Zero)
        {//Cycle through dialogs (not working)
            if(MdlWrappers.mdlWindow_isModal(current))
            {
                current = MdlWrappers.mdlDialog_getNext(current);
                int close = MdlWrappers.CloseCommandQueue(); //Not sure if this works yet
            }
        }
        
        //2: Works - but no modal windows found
        IntPtr current = MdlWrappers.mdlWindow_getFirst();
        while (current != IntPtr.Zero)
        {//Cycle through available windows (working)
            if(MdlWrappers.mdlWindow_isModal(current))
            {
                int close = MdlWrappers.mdlWindow_close(current, 2, false); //Not sure if this works yet
            }
            current = MdlWrappers.mdlWindow_getNext(current);
        }
    });
}

I also just found this article but it seems a bit outdated: https://communities.bentley.com/products/microstation/w/askinga/440/keyins-to-toggle-dialogs-and-toolboxes-pre-v8 - perhaps there is a similar option to this to find and then close them out via keyin?

Thanks,

Edward

Parents Reply Children
  • Out of the box MicroStation does not offer too much, I think only very simple IPC interface, allowing to send key-ins, is available

    Yes I am just using this basic interface provided in the SDK example but customised to suit what I need

    How it can happen a modal dialog opens? Do you use key-ins to control MicroStation and some tool that you start opens such dialog?

    Yes that's correct I'm simply using key-ins to control MicroStation, and every now and again a modal dialog will be opened requesting input (and blocking execution). For example if using the OpenBuildings engine to open an OpenBridge file, when closing the file it might prompt if I want OpenBuildings to take ownership of the file and save (can't remember the exact words but hopefully you get what I mean!)