Hi I am trying to implement a windows service that subscribes and publishes to IObservables.
I have used http://blogs.tedneward.com/2010/11/20/Windows+Service+In+F.aspx from Ted Neward’s blog as a starting point.
type WindowsService() as this
let createAndPublishObservables() =
let obs1 = createObservable1()
let obs2 = createObservable2()
let combObs = Observable.CombineLatest(obs1, obs2) |> map ( fun (firstObsValue, secObsValue) -> firstObsValue + secObsValue)
let obsUpdater = new ObsUpdater()
let updaterPublish = combObs.subscribe( fun x -> obsUpdater.publish(x), ignore, fun () -> ())
override this.OnStart(args:string[])
base.OnStart(args)
// and so on....
when I try to debug this code, it seems as if the service finishes its execution and the subscribers and publishers go out of scope (so the reactivity disappears).
Do I need to add something additionally like a message pump to get this to work? (had it working on a windows form but moving to a service has so far not been successful so far.)
Thanks for help!
If you don’t do anything in your Windows Service, it will exit directly after OnStart. You need to keep your application alive. A common way to do this is to spawn a separate thread that will do your processing indefinitely. Then, stop the thread somehow in OnStop to make the service die.
Make sure that the thread is not a background thread. If it is, it won’t keep the app alive.
I’m not sure what you mean when you say that your service will publish observables. Who is going to subscribe to those observables?