Replace Monitor by Semaphore
working directory for windows service

also refactoring and logging