I need to read data from reader continuously and send it to the caller. I created self hosted window service to act as a signalR. I started infinite loop inside it.
public void ReadTags()
{
try
{
while (true)
{
var store = Reader.Read();
var tags = store.ToArray();
Clients.Caller.getTagsRead(tags);
System.Threading.Thread.Sleep(500);
}
}
catch (Exception ex)
{
System.Diagnostics.EventLog.WriteEntry("Send", ex.Message + "\n" + ex.StackTrace);
}
}
Now, I want to have a control on this method to be able to pause, play or stop this loop next time when a method is invoked. Since Hub creates an instance everytime, this means loop will be running under a different instance.
How can I achieve this?