Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Please consider replacing the "There only can be one instance of NinjaTrader" error

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

    Please consider replacing the "There only can be one instance of NinjaTrader" error

    I find the current "Error There only can be one instance of NinjaTrader running at a time (NinjaTrader/2)." error message and subsequent paragraph to be a bit jarring:



    Please consider replacing this error message with the behavior of focusing on the currently running instance of NinjaTrader. That way when the user double-clicks on NinjaTrader wanting to go to NinjaTrader the user is taken to NinjaTrader.

    Here is C# that will focus on the currently running instance of NinjaTrader:
    Code:
    bool successfullyAcquiredNinjaTraderMutex;
    using (new Mutex(true, "NinjaTrader.exe", out successfullyAcquiredNinjaTraderMutex))
    {
      if (successfullyAcquiredNinjaTraderMutex)
      {
        Application.Run(new NinjaTraderMainForm());
      }
      else
      {
        IntPtr soleInstanceOfNinjaTrader
          = Process.GetProcessesByName("NinjaTrader")[0].MainWindowHandle;
        SetForegroundWindow(soleInstanceOfNinjaTrader);
      }
    }
    
    [DllImport("user32.dll")]
    private static extern bool SetForegroundWindow(IntPtr windowHandle);

    #2
    Thanks for the suggestion and for kindly providing code sample.
    RayNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by kinfxhk, 07-13-2026, 10:18 AM
    0 responses
    28 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-13-2026, 09:50 AM
    0 responses
    18 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-13-2026, 07:21 AM
    0 responses
    26 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by kinfxhk, 07-11-2026, 02:11 AM
    0 responses
    24 views
    0 likes
    Last Post kinfxhk
    by kinfxhk
     
    Started by SalmaTrader, 07-07-2026, 10:26 PM
    0 responses
    139 views
    0 likes
    Last Post SalmaTrader  
    Working...
    X