I am currently working on a Windows Service that does a database call and does some work and then waits for several seconds to run again. I have to connect to a database during the work and I would like to keep the database connection somewhere that I know will be cleaned up when the object is done.
I was thinking of using something like HttpContext but obviously Windows Services do not have anything like that. What is the best way to make sure my connections are disposed properly after each call?
There is always fallback to static properties possible. So you can keep it in a static variable on a class.
However, this is not good practice. It seems that you need to:
Best is to use TPL:
Task<T>.