c# - Does ServiceBase.Run(ServiceBase[] ) method run all services in array asynchronously? -


servicebase[] servicestorun;             servicestorun = new servicebase[]             {                 new service1(),                 new service2()             };             servicebase.run(servicestorun); 

how work? service1 run, , when onstart() done, service2's onstart() run, or both of them run @ same time? if that's case, , explicitly want service1's onstart done before running service2.onstart(), how go?

would trick:

servicebase.run(new service1()) servicebase.run(new service2()) 

you misunderstanding servicebase.run() does.

from the documentation:

registers executable multiple services service control manager (scm).

the sequence goes this:

  • a start request received 1 (or perhaps both) services.
  • the scm launches executable.
  • your main function calls servicebase.run().
  • the scm calls onstart() service matching start request, in new thread. unless both services being started, onstart() not called other one!

if both services are being started order in onstart() called indeterminate, unless 1 service has been configured have dependency on other. configuring such dependency safe way ensure particular ordering, trickery such waiting in 1 onstart() signal other 1 may cause scm deadlock.

if 1 service started, , later on other service started, scm call onstart() second service @ point.

note can call servicebase.run() once (your executable expected exit promptly once returns) second code segment wrong; code prevent service2 running @ all.

also, note if 2 services cannot run independently of 1 another, there no point in having 2 services in first place. case think of sensible if want user able stop , start service2 while leaving service1 running.


Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -