javascript - Optimalisation of displaying data in real time in ASP.NET MVC -
long story short, trying display real time data, using asp.net mvc , eventhubs.
i have async method in controller receiving messages hub , placing them in class-variable. views on other hand using js retrieve value , value div tag js based chart can retrieve value read innerhtml value of div.
i feel not way work, , feels system unstable @ times, please take @ code better understanding:
methods of interest found in controller:
public async static void updatelist() { { try { var message = await consumer.receiveasync(); if (message != null) { //alot of code receive needed double } } catch (exception exception) { console.writeline("exception on receive {0}", exception.message); } } while (true); } public async task<actionresult> refreshlatest() { //code pass needed double view return partialview("latest", latest); }
then there view, generated refreshlatest method:
@model double <div id="templivedata" style="display:none;">@model</div>
and in loaded view js part of graph grabs value:
setinterval(function () { try { line1.append(new date().gettime(), document.getelementbyid('templivedata').innerhtml); } catch (err) { console.log("stream not started"); } }, 200);
last not least, code triggers refreshlatest method in index view:
<script type="text/javascript"> $(function () { setinterval(function () { $('#latest').load('/stream/refreshlatest'); }, 200); }); </script>
so code working, wondering if there way this.
it looks use signal r -> [http://signalr.net ] made handle real time messages. have look.
Comments
Post a Comment