Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

lock (Account.All)

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

    lock (Account.All)

    Hello.
    I am trying to understand the purpose of the lock statement in the example under the NinjaScript Language Reference "Account" just underneath "// Find our Sim101 account."

    Thank you.

    Dan.

    #2
    Hello Dan,

    The lock() method is to prevent an object (in this case a collection of all accounts) from being accessed as it is being modified.

    More specifically:
    "The lock keyword ensures that one thread does not enter a critical section of code while another thread is in the critical section. If another thread tries to enter a locked code, it will wait, block, until the object is released."

    In this case, this is to prevent a 'Collection was modified after the enumerator was instantiated' error.

    Below is a link to a forum post that discusses.
    https://ninjatrader.com/support/foru...06#post1099406

    Below is a link to the Microsoft documentation and to links to educational sites.
    https://docs.microsoft.com/en-us/dot...lock-statement
    https://stackoverflow.com/questions/...k-work-exactly
    https://stackoverflow.com/questions/...90569#23090569
    Last edited by NinjaTrader_ChelseaB; 08-01-2022, 08:00 AM.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by DJ888, Today, 10:57 PM
    0 responses
    1 view
    0 likes
    Last Post DJ888
    by DJ888
     
    Started by MacDad, 02-25-2024, 11:48 PM
    7 responses
    158 views
    0 likes
    Last Post loganjarosz123  
    Started by Belfortbucks, Today, 09:29 PM
    0 responses
    7 views
    0 likes
    Last Post Belfortbucks  
    Started by zstheorist, Today, 07:52 PM
    0 responses
    7 views
    0 likes
    Last Post zstheorist  
    Started by pmachiraju, 11-01-2023, 04:46 AM
    8 responses
    151 views
    0 likes
    Last Post rehmans
    by rehmans
     
    Working...
    X