Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

"System.Threading.LockRecursionException" error in NT8

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

    "System.Threading.LockRecursionException" error in NT8

    I try to fire two consecutive (at the same time) MessageBox.Show().
    in NT, the script stops execution and I get the following message:

    "Failed to call 'Add' method: System.Threading.LockRecursionException: Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Please ensure that read locks are released before taking a write lock. If an upgrade is necessary, use an upgrade lock in place of the read lock. at System.Threading.ReaderWriterLockSlim.TryEnterWrit eLockCore(TimeoutTracker timeout) at System.Threading.ReaderWriterLockSlim.TryEnterWrit eLock(TimeoutTracker timeout) "


    what are remedies? should i fire MessageBox.Show() in "invoke", to avoid Thread locking?
    Last edited by ttodua; 08-29-2018, 01:56 AM.

    #2
    Hello TazoTodua,

    Thanks for your post.

    Calling MessageBox.Show() will lock the current thread. Depending on how this is called, it would be possible to encounter such an error.

    You could use a Dispatcher to avoid the error, but you would not be locking that thread and likely not achieve your intended result. This can be tested with the code below to observe what the result will be:
    Code:
    this.Dispatcher.InvokeAsync(new Action(() => {
    // Your code here
    }));
    From a NinjaTrader perspective, I would like to point out the built in Alert methods we offer which would be recommended for firing alert message box windows.

    I've included publicly available reference for using Alerts and for Multi Threading Considerations.

    Alert() - https://ninjatrader.com/support/help...n-us/alert.htm

    MultiThreading Considerations - https://ninjatrader.com/support/help...-threading.htm

    Please let us know if we can be of further assistance.
    JimNinjaTrader Customer Service

    Comment


      #3
      Jim, thanks! ! !

      one question - the Alert() functionality is not as we imagine.
      in other Trading platforms, the Alert() fires a visual message/popup box,
      but in NT, it's only logged into the backend AlertLog window, with sound.
      but i wanted to have a Popup-box like message.

      it was good, that likely to other platforms, NT has also it's method to fire the popup/messageboxes, with alert.

      can you submit that to developers, to create a simple message/popupbox, and could be called with Alert() function (you might need to create another overload for alert(), accepting the true/false as the argument to show/dont-show that messagebox).

      btw, at this moment, i am using custom simple c# `Form` instead of `MessageBox.Show()`

      Comment


        #4
        Hello TazoTodua,

        I had mistaken Chart Alert functionality with the NinjaScript method. My apologies for any confusion. I've submitted your request and the ticket ID is SFT-3478.

        Also to point out, you can create your own windows through NinjaScript. I'll provide a link to a related thread and reference for creating windows in NinjaTrader.

        Opening a window from a strategy - https://ninjatrader.com/support/foru...ad.php?t=78876

        AddOn Development Overview - https://ninjatrader.com/support/help...t_overview.htm

        Please let us know if we can be of further assistance.
        JimNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Barry Milan, Today, 10:35 PM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by WeyldFalcon, 12-10-2020, 06:48 PM
        14 responses
        1,428 views
        0 likes
        Last Post Handclap0241  
        Started by DJ888, Yesterday, 06:09 PM
        2 responses
        9 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by jeronymite, 04-12-2024, 04:26 PM
        3 responses
        40 views
        0 likes
        Last Post jeronymite  
        Started by bill2023, Today, 08:51 AM
        2 responses
        16 views
        0 likes
        Last Post bill2023  
        Working...
        X