0

I have a function A that loops every second up till 120 seconds and calls a plotting function B that generates chart using XPlot.Plotlyand returns the html string of that chart. The function A gets the html and gives input to the webBrowser element that displays the chart in the form.

However, every second when it loops the browser blanks out and shows the new html chart. This is a bit annoying. Is there a way where I can seamlessly update the html in the web browser element. I am trying to achieve a live-plot scenario. The code is given below,

private async void simpleButton3_Click(object sender, EventArgs e)
{
    LiveEnvelopeChartGenerator liveEnvelopeChartGenerator = new LiveEnvelopeChartGenerator(23476, 7);
    string lastCycleTimestamp = liveEnvelopeChartGenerator.GetLastCycleEndTime();
    for (int i = 0; i < 121; i++)
    {                
        var currentAttrData = liveEnvelopeChartGenerator.GetLatestAttributeValuesFromLastCycleEndTime(lastCycleTimestamp, i);
        string html = liveEnvelopeChartGenerator.PlotTraces_(currentAttrData); // gets the html string               
        await Task.Run(() => this.webBrowserLiveEnvelope1.DocumentText = html);
        //System.Threading.Thread.Sleep(1);
    }
}
VLAZ
  • 26,331
  • 9
  • 49
  • 67
Murtaza
  • 413
  • 1
  • 3
  • 13
  • How I would do it is to pass the HTML [from C# to my own JavaScript function](https://stackoverflow.com/q/27252703/107625) inside the WebBrowser control and then process it further inside this JavaScript function. – Uwe Keim Mar 02 '22 at 09:32
  • I have no experience with JavaScript. Is there an alternative way? – Murtaza Mar 02 '22 at 09:36
  • No, there isn't -- `await Task.Run(() => this.webBrowserLiveEnvelope1.DocumentText = html);`: really? – Jimi Mar 02 '22 at 09:54
  • @Jimi If I don't use await the web browser does not show a thing. It shows only at the end of the loop. – Murtaza Mar 02 '22 at 09:57

0 Answers0