I have a page waiting for response of a Generic Handler with this javascript code:
if (typeof (EventSource) !== "undefined") {
var source = new EventSource("../Handler/EventHandler.ashx");
source.onmessage = function (event) {
alert(event.data);
};
}
and this handler:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/event-stream";
context.Response.Write("data: Event handler started");
context.Response.Flush();
context.Response.Close();
}
Now I want to have a method (in handler) ,like this to send some real-time data through ashx to my page:
public void send(string data){
//send through ashx
}
How can I write this method to be callable from other classes? Can I use thread?