Forum Discussion
AharonBensadoun
Nov 09, 2021Copper Contributor
How to add a timer to C# Service
Hi everyone I am new to coding in c # and trying to write a windows service in c #, my service seems to be working fine except for one thing: I try to make it run in a loop, say every 30 seconds, a...
RobIII
Nov 09, 2021Copper Contributor
Please post only relevant code next time. The only relevant part is lines 177-188, the rest is irrelevant to your question.
Your timer gets disposed when main is exited; you need to pull it (it being the timer variable) out of main and make it a class member (so make it a private field on Service_PSTest for example) or find another way to keep the instance 'alive'.