locked
Plot data in a Chart when receiving from method running in a different thread! RRS feed

  • Question

  • User-1540960300 posted

    Hi there! I´m having problems to plot data on a web chart when I receive it from M2MQTT library (client_MqttMsgPublishReceived method) which run in a different thread. I have used the same library for a desktop application, and in these case using Dispatcher. Invoke I have solved this problem. I am new programming web application so have been so difficult to solve this ploblem. When I debug the code the messages are being received OK, so the problem is when trying to plot it in the chart.

    Thanks in advance for your help!

    Monday, November 18, 2019 11:39 AM

All replies

  • User-719153870 posted

    Hi ernesto_gf,

    When I debug the code the messages are being received OK, so the problem is when trying to plot it in the chart.

    We could use the code where you're trying to plot the chart. Also, please provide sample data which you want to plot in the chart which you said received OK when you debugged it.

    Best Regard,

    Yang Shen

    Tuesday, November 19, 2019 3:08 AM
  • User-1540960300 posted

    Hi Yang Shen,

    I have a method which plot the data taking data from a string. When I use this method in the Page_Load method it works but when calling it from the received data method I obtain a NullObjectReference error refered to the Chart. The received data method run in a different thread and I think this is the problem. For a desktop application this problem is easy to solve by using Dispatcher.Invoke but I don´t know how to develop something similar on a web application.

    Tuesday, November 19, 2019 8:35 AM
  • User-1540960300 posted

    These is the received data  method from which the chart is not accesible and give NullReferenceException

    public void client_MqttMsgPublishReceived(object sender, MqttMsgPublishEventArgs e)
    {
        ReceivedMessage = Encoding.UTF8.GetString(e.Message);
            
    
    }

    Tuesday, November 19, 2019 9:09 AM