Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Problem with Dispatcher.InvokeAsync

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

    Problem with Dispatcher.InvokeAsync

    Hi

    I'm finding and getting a window state with:

    Code:
    // Loop through all NT windows to find the SuperDOM window
    foreach (var window in NinjaTrader.Core.Globals.AllWindows)
    {[INDENT]// Check if the found window is the one required
    if (!(window is NinjaTrader.Gui.SuperDom.SuperDom)) continue;
    
    window.Dispatcher.InvokeAsync(new Action(() =>
    {[/INDENT][INDENT=2]// Try to cast as the required type of window, if it fails it will be null
    foundSuperDom = window as NinjaTrader.Gui.SuperDom.SuperDom;
    
    // Check we found a SuperDOM
    if (foundSuperDom == null) return;
    
    // Restore/minimize SuperDOM window
    if (foundSuperDom.WindowState == System.Windows.WindowState.Minimized)
    {[/INDENT][INDENT=3]foundSuperDom.WindowState = System.Windows.WindowState.Normal;
    isSuperDomMinimized = false;[/INDENT][INDENT=2]}
    else
    {[/INDENT][INDENT=3]foundSuperDom.WindowState = System.Windows.WindowState.Minimized;
    isSuperDomMinimized = true;[/INDENT][INDENT=2]}[/INDENT][INDENT]}));[/INDENT]
     
     }
    
    Print(isSuperDomMinimized);
    without any issue.

    The problem I have is
    Code:
    Print(isSuperDomMinimized);
    runs before the looping through the windows. How I do I get the Print statement to run after the looping through the windows?

    #2
    Not to worry, I've found the solution.
    It's all down to accessing the correct thread using the correct dispatcher.

    Comment


      #3
      Hello FatCanary,

      Dispatcher.InvokeAsync is asynchronous. This means the code is running on another thread. If you want a thread blocking invoke you can use Dispatcher.Invoke(), however keep in mind this can cause deadlocks.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Yep, thanks Chelsea.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        647 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        368 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        108 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        571 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        573 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X