DÜZENLEME: Bu yalnızca bir .exe hizmetini çalıştırırken değil, çalışırken çalıştırılır. Alternatif olarak bir yapılandırma değeri olarak seçeneğini ekleyebilirsiniz ve (muhtemelen daha iyi bir uygulama zaten olan) Başlangıçta okumak:
using System.Configuration;
// snip
string foobar = null;
HostFactory.Run(configurator =>
{
foobar = ConfigurationManager.AppSettings["foobar"];
// do something with fooBar
configurator.Service<ServiceClass>(settings =>
{
settings.ConstructUsing(s => GetInstance<ServiceClass>());
settings.WhenStarted(s => s.Start());
settings.WhenStopped(s => s.Stop());
});
configurator.RunAsLocalService();
configurator.SetServiceName("ServiceName");
configurator.SetDisplayName("DisplayName");
configurator.SetDescription("Description");
configurator.StartAutomatically();
});
bu komutları belirtmek gerekir belgelere göre desen:
-foobar:Test
Ayrıca servis yapılandırmasında tanımını eklemek gerekir
:
string fooBar = null;
HostFactory.Run(configurator =>
{
configurator.AddCommandLineDefinition("fooBar", f=> { fooBar = f; });
configurator.ApplyCommandLine();
// do something with fooBar
configurator.Service<ServiceClass>(settings =>
{
settings.ConstructUsing(s => GetInstance<ServiceClass>());
settings.WhenStarted(s => s.Start());
settings.WhenStopped(s => s.Stop());
});
configurator.RunAsLocalService();
configurator.SetServiceName("ServiceName");
configurator.SetDisplayName("DisplayName");
configurator.SetDescription("Description");
configurator.StartAutomatically();
});
AddCommandLineDefinition() 'dan sonra ve/veya aşağıdaki satırı eklemeniz gereken bir şey yapmadan önce: configurator.ApplyCommandLine(); – Todd
ServiceClass'a bir komut satırı bağımsız değişkeni ekleyebilir misiniz? Bunu yapmaya çalışıyorum, ancak bir hizmet olarak başladığımda çalışmaz. – fuLLMetaLMan
Evet. Bu, hizmet olarak kurulurken/başlatıldığında çalışmıyor. foobar boş. @fuLLMetaLMan: Bir cevap buldunuz mu? –