2

I am recently trying to combine C# and JavaScript together in client side only. I follow the instruction in here to invoke functions in a C# DLL in JavaScript. Now I have a question regarding push data from C# DLL to JavaScript. Suppose the C# DLL includes a function collecting data from a sensor periodically (30 data every second). I would like to draw the data in a browser by pushing the data from the DLL to JavaScript and then draw in the website page. Can anyone suggest a possible way to solve this problem? Thank you.

1 Answer 1

2

One method can be to create a TCP server on the C# client/server application and connect to the server from JavaScript; after which, you can send the data.

You can also create a web socket with JavaScript and then send data to that via the ActiveX control. Executing it in ActiveX, then sending the queries. http://www.codeproject.com/Articles/617611/Using-WebSocket-in-NET-4-5-Part-1

A problem with both of these solutions is the fact that you can't use DLL's ONLY to do that, you need a service/pooling service.

The best method to do this (which may/not work for your specific case) is to create a simple server with C# and then use an observable model in JS to fetch and render the data. This way, you can get rid of the code which checks if the data is being sent and see the changes in real-time.

Use a framework like AngularJS and you'll be off. https://docs.angularjs.org/api/ng/directive/ngModel

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you. However, because the C# code involves a driver that drives a sensor to collect data, I am not able to run it in a server and then use it to drive a sensor in client side. So I think building a server may not be a good option for me though it may be a very good solution for other cases. I would like to invoke C# DLL in JavaScript. In C# DLL, for example, there is a thread running continuously to retrieve data from a sensor and then pump it to JavaScript using a technique like event in C# or a asynchronous way to have a call back function. I am not sure if such method exists. Thanks
@Ben - were you able to find a solution to this?
@niksvp, I eventually choose to run a smaller console application with websocket on in client side to capture data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.