Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Using dispatcher in NT8

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

    Using dispatcher in NT8

    Hello together,

    I have a running strategy with NT7 and now, I do the jump to NT8. My problem is, that my threadning to an external source doesn´t work in NT8. I need some help with the dispatcher:

    Under State.Configure I can establish a confirmed connection:
    Code:
    		if (State == State.Configure)
    			{
    				Configuration config = new Configuration();
    				config.Symbol = "Test";
    				Connect("xxx.x.x.x", xxxx, config);				
    			}
    In the section OnBarUpdate(), I send the data to the external source. This source does some calculations and send an object back (outside the OnBarUpdate() )

    Under NT7 everything works fine. Also under NT8 I can establish a connection. With NT8 I learned, that I have to use a dispatcher and the ApartmentState.STA:

    Code:
    		protected override void OnBarUpdate()
    			{
    				Owner.Dispatcher.BeginInvoke(new Action(() =>
            	    		{
    					DefineSendData1();
    		        	        DefineSendData2();
    		       		}));
    
    			}
    In the source code to establish the connection I added:

    Code:
    		patternThread.SetApartmentState(ApartmentState.STA);
    Setting the Dispatcher and the ApartmentState.STA the warning:
    "Error on calling the OnBarUpdate()... The calling thread must be STA disappears."

    But now I get the warning:
    "Error on calling the OnBarUpdate()... Object reference not set to an instance of an object."


    I have two questions:
    - Is there any major change in Threadning, that I have to write the Threadning part completly new? Or
    - do I have to do only minor changes to get my old code running in NT8?

    I would be happy for some help.

    Thanks
    uupsa!

    #2
    In the meanwhile, I have an improvement. With the following code, there is no failure message anymore:

    System.Windows.Threading.Dispatcher.CurrentDispatc her.BeginInvoke(new Action(() =>
    {
    Log("Test of Threadning", LogLevel.Information);
    DefineSendData1();
    DefineSendData2();
    }));
    But the the data won´t be executed. I have no Log entry and the methods are not executed.

    uupsa

    Comment


      #3
      Hello,

      Thank you for the questions.

      There have been changes to the threading in NT8, it is now multi threaded. Regarding if you would only have to do minor changes, that would depend being that this is not a standard NinjaScript item it is possible that it does work in NT7 but not NT8 depending on the library and code used.

      The error you provided: Error on calling the OnBarUpdate()... Object reference not set to an instance of an object.

      This would relate to an object being null while trying to be accessed, have you further determined if this is one of the objects you are using or is this coming from your external library? Or is this caused when you add the Apartment state in? it could be an inherited object you are using that is not populated by changing the apartment.

      It would be hard to say what specifically is happening in this scenario, you would need to further debug the syntax being used to see what is null that is being accessed or if this is coming from the external library.

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Orion815, 05-02-2024, 08:39 AM
      2 responses
      15 views
      0 likes
      Last Post Orion815  
      Started by suroot, 02-25-2017, 04:43 AM
      11 responses
      2,548 views
      0 likes
      Last Post Zilvercat  
      Started by Rogers101, 05-05-2024, 11:30 AM
      16 responses
      50 views
      0 likes
      Last Post Rogers101  
      Started by ninza33, Today, 12:31 PM
      2 responses
      10 views
      0 likes
      Last Post ninza33
      by ninza33
       
      Started by Bobin, 03-12-2024, 08:51 AM
      15 responses
      483 views
      0 likes
      Last Post fiddich
      by fiddich
       
      Working...
      X