Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I might suggest a slightly altered pattern for your service, anyway; where we have a <code>readonly</code> <code>Timer</code>, which, after initial assignment, simply gets <em>toggled</em> to run as opposed to the way disposing is occurring at the minute, and also keep our own hard reference to the <code>TimerCallback</code>. LAstly, we leave the disposing of objects up the to service itself (at least the long term objects we're bothered about).</p> <p>Although this pattern may not be a white rabbit from a hat in your case, I can vouch for the reliability of many services constructed in this manner. Therefore, if problems ensue even after implementation of such then I would be highly confident in saying that what follows <code>// Processing code here</code> is, in and of itself, problematic.</p> <pre><code>private readonly System.Threading.Timer Timer = null; private readonly System.Threading.TimerCallback Callback = null; private readonly int Interval = 5000; public MyService() { Callback = new TimerCallback(this.timerPublish_Elapsed); Timer = new System.Threading.Timer(Callback, null, Timeout.Infinite, Timeout.Infinite); } private void Start() { Timer.Change(Timespan.Zero, Interval); } private void Stop() { Timer.Change(Timeout.Inifinite, Timeout.Inifnite); } protected override void OnStart(string[] args) { Start(); } protected override void OnStop() { Stop(); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private void Dispose(bool disposing) { if(disposing) { if(Timer != null) Timer.Dispose(); } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload