My programmed extension (windows forms) for masshunter freezes when opened

Hi,

I programmed a module/extension (windows forms) for masshunter quantitative analysis.

When I use my self-programmed module while I'm in the Visual Studio Masshunter test environment, it works. BUT if I start the normal masshunter quantitative analyse software, it doesn't work. My windows form is freezing and windows tells me that my module can't/doesn't recognize.

I use the code:
FormX.Show()
When I use the code .ShowDialog(), it doesn't freeze and I can use my windows form. But then the synchronize navigation in masshunter doesn't work anymore. It works again when I closed my windows forms.

I tried it out with a MessageBox, too. There is the same situation.

What did I wrong?

EDIT: It seems that the navigation synchronize is working, but the "Current Compound" (see picture below) doesn't work anymore.

When I'm using the .ShowDialog()-method in my self-programmed window it doesn't work like a dialog-window. It works like a normal window.

Parents
  • Hello  ,

    I am able to run this simple Show() example from IronPython: First steps - Simple Talk (red-gate.com) as-is in Version 10.2 of quant. I tested with CAG and linked navigation without issue. So I don't believe what you are observing with Show() is an issue with quant or the SDK.

    import clr
    clr.AddReference('System')
    clr.AddReference('System.Windows.Forms')
    import System
    import System.Windows.Forms as WinForms
    message = "Cancel this operation?"
    caption = "Alert"
    buttons = WinForms.MessageBoxButtons.YesNo
    result = WinForms.MessageBox.Show(message, caption, buttons)
    if result == WinForms.DialogResult.Yes:
        WinForms.MessageBox.Show("Great, it's canceled!")
        System.Console.Write("Success!")
    else:
        print "Sorry, something went wrong!"
    It is possible that the debug/test environment is trapping some warning or error that is causing the issue you are observing in your live quant. You may need to go back and add features/functions one at a time and check in the test environment and live quant to isolate the issue.
  • Yes, I also tested the code a few minutes ago. The same problem exists here.

    Usually the MessageBox has the behavior like a dialog form.
    But the MessageBox has not a .ShowDialog() command, only a .Show() command (I looked in the microsoft documentation on https://learn.microsoft.com/en-us/dotnet/api/system.windows.messagebox?view=windowsdesktop-8.0)

    It's actually impossible to click in the parent form and in the CAG window while you have the MessageBox open.


    For example:
    I open the module in my test environment in Visual Studio. The MessageBox behaves like a dialog form (this is correct).
    But if I start the module in a separate Masshunter without the test environment, then it doesn't behave like a dialog form.

  • As you state, the MessageBox.Show() act as if modeless - but the MessageBox.Show() is not modeless, I don't know the correct term, but something with Threads and Async... And in Visual Studio you likely have a common parent, that makes it act as you except.

    Anyway. this MessageBox behaviour becomes clear when one MessageBox opens another MessageBox - and then is modal...

    So, to get the first MessageBox to be modal as expected, you need to define a function with the logic, wrap it as an action, and then use the UIState.SynchronizeInvoke, see modified example below:

    import clr, UIState
    clr.AddReference('System')
    clr.AddReference('System.Windows.Forms')
    import System
    import System.Windows.Forms as WinForms
    message = "Cancel this operation?"
    caption = "Alert"
    buttons = WinForms.MessageBoxButtons.YesNo
    def ShowModalMessage():
        result = WinForms.MessageBox.Show(message, caption, buttons)
        if result == WinForms.DialogResult.Yes:
            WinForms.MessageBox.Show("Great, it's canceled!")
            System.Console.Write("Success!")
        else:
            print "Sorry, something went wrong!"
    act = System.Action(ShowModalMessage)
    UIState.SynchronizeInvoke.Invoke(act, None)

     

    I am not sure whether this solves your original question - but it might explain some of the behavior. For your form you should try to use ShowDialog() or Show() wrapped in the same manner, to get the behavior you want.

Reply
  • As you state, the MessageBox.Show() act as if modeless - but the MessageBox.Show() is not modeless, I don't know the correct term, but something with Threads and Async... And in Visual Studio you likely have a common parent, that makes it act as you except.

    Anyway. this MessageBox behaviour becomes clear when one MessageBox opens another MessageBox - and then is modal...

    So, to get the first MessageBox to be modal as expected, you need to define a function with the logic, wrap it as an action, and then use the UIState.SynchronizeInvoke, see modified example below:

    import clr, UIState
    clr.AddReference('System')
    clr.AddReference('System.Windows.Forms')
    import System
    import System.Windows.Forms as WinForms
    message = "Cancel this operation?"
    caption = "Alert"
    buttons = WinForms.MessageBoxButtons.YesNo
    def ShowModalMessage():
        result = WinForms.MessageBox.Show(message, caption, buttons)
        if result == WinForms.DialogResult.Yes:
            WinForms.MessageBox.Show("Great, it's canceled!")
            System.Console.Write("Success!")
        else:
            print "Sorry, something went wrong!"
    act = System.Action(ShowModalMessage)
    UIState.SynchronizeInvoke.Invoke(act, None)

     

    I am not sure whether this solves your original question - but it might explain some of the behavior. For your form you should try to use ShowDialog() or Show() wrapped in the same manner, to get the behavior you want.

Children
  • As you state, the MessageBox.Show() act as if modeless - but the MessageBox.Show() is not modeless, I don't know the correct term, but something with Threads and Async... And in Visual Studio you likely have a common parent, that makes it act as you except.

    Thanks for your hint!

    I have never written modules for external programs before, so I was a bit surprised.
    I had also read up on StackOverflow and now I'm a bit smarter about this topic.

    I can assign the main window to the MessageBox. So it reacts as I expect. Otherwise I can use the SynchronizeInvoke-method.

    I think the SynchronizeInvoke function is the reason why masshunter UI can update the "current compound"-field while I'm using the CAG window. Before I didn't use the SynchronizeInvoke-function and I was wondering why the masshunter UI didn't update the "current compound"-field while I was using the CAG window.

Was this helpful?