Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

NTMessageBoxSimple not halting script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    NTMessageBoxSimple not halting script

    I need to check the data in a database for errors before using the data. I've added an NTMessageBoxSimple which will be displayed when an error in the database is found. I assumed that the messagebox would display, halt the script progress, allow me to correct any discrepancies, and the proceed with script. Instead the script runs past the NTMessageBoxSimple.Show and the script halts with an out of bounds exception message when the database error is encountered and then the NTMessageBox displays. Is there a way to force the MessgeBox to display when the NTMessageBoxSimple.Show() line is hit? The code is in an AddOn and I get a compile error when I try to add ForceRefresh().
    Thanks in advance,

    Code:
                                if (
                                    entry.IsEntry   != entry.IsEntryStrategy  ||
                                    entry.IsExit    != entry.IsExitStrategy    ||
                                    entry.Name      == null      
                                    )
    ​                            {
                                       cc.Dispatcher.InvokeAsync(new Action(() =>
                                      {
                                               NinjaTrader.Gui.Tools.NTMessageBoxSimple.Show(Window.GetWindow(cc.OwnerChart as DependencyObject),
                                                "\r\n" +
                                                "                              Discrepancy in DataBase\n\n" +
                                                "                                   Check ID # " + ID,
                                                "               AddOns.Methods.getInstList() Line " + LN(),
                                                MessageBoxButton.OK, MessageBoxImage.Error);
                                       }));​
                                }
    ​

    #2
    Hello ramckay,

    The recommended approach would not be to halt the thread but to trigger an action when the user clicks ok (the .Show() method returns a MessageBoxResult value​).

    The calling method would return after showing the message box this so it's no longer doing anything.

    This would thus wait for the user to click OK before continuing actions.

    You could also set a bool variable just before showing the message box to suppress any other asynchronous methods running from a different thread and set this back once the user clicks OK.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,
      I'm trying to get the message box to show when a condition is met. Initially I tried .Show(); System.Environment.Exit(0); I was expecting the message box to show. It would contain information about what needed to be fixed in the database which I could resolve and then restart the app. What happens is that the MessageBox never shows and NT shuts down. I tried putting the 'System.Environment.Exit(0);' line in another method and got the same results - program shuts down and messagebox never shows.
      Thanks

      Comment


        #4
        Hello ramckay,

        It sounds like you are shutting down the application.

        If the application is shutdown the message box isn't going to show.

        If you want the message box to show don't shut down the application.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Chelsea,
          It sounds like you are shutting down the application.

          If the application is shutdown the message box isn't going to show.​
          No. What I'm trying to do is have the messagebox show when a condition is met. Can an NT script be halted with a messagebox? I showed the code to shut down the app. I didn't show the the other 5 efforts I tried when attempting to get the message box to show and stop the scripts progress. Is there a way to do this?
          Thanks

          Comment


            #6
            Hello,

            You stated in post # 3 you are calling System.Environment.Exit(0); to shutdown the application.

            Don't.

            "Can an NT script be halted with a messagebox?"

            Not that I know of. You are calling this on a different thread that runs asynchronously.


            "I showed the code to shut down the app."

            Right. I'm directing you to not shutdown the NinjaTrader application.

            "I didn't show the the other 5 efforts I tried when attempting to get the message box to show and stop the scripts progress. Is there a way to do this?"

            The recommended approach would not be to halt the thread but to trigger an action when the user clicks ok.
            The desired outcome of nothing happening until the user clicks ok would be achieved.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Hello,
              The crux of the matter here is what initiates the display of the MessageBox and can I somehow control it?
              Thanks

              Comment


                #8
                Hello ramckay,

                You can control when the method is called. But that I know of you wouldn't be able to halt the NinjaScript while waiting for the UI thread code to complete. They are asynchronous.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  ChelseaB,
                  I did that and it works well.
                  Thanks

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  558 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  324 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  545 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  547 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X