기본 Windows 서비스에서 원하는 수의 하위 서비스를 시작할 수있는 하위 서비스 모델을 만들고 싶습니다.
public interface ISubService
{
void Initialize(XmlElement xmlSection);
bool Start();
void RequestStop();
void Stop(TimeSpan timeout);
}
그리고 어쩌면 기본 스레드 서비스 클래스 ..
public abstract class ThreadedService : ISubService
{
private Thread m_thread;
private ThreadedService()
{
m_thread = new Thread(new ThreadStart(StartThread));
}
// implement the interface
}
는 설정 섹션을 처리 할 ...의 app.config과 IConfigurationSectionHandler를 통해
public class ServiceConfigurationHandler : IConfigurationSectionHandler
{
public ServiceConfigurationHandler() { }
public object Create(object parent, object configContext, XmlNode section)
{
return new ServiceConfiguration((XmlElement)section);
}
}
뭔가를 당신의 서비스 구성 ...
public class ServiceConfiguration
{
public static readonly ServiceConfiguration Current = (ServiceConfiguration)ConfigurationManager.GetSection("me/services");
private List<ISubService> m_services;
private string m_serviceName;
internal ServiceConfiguration(XmlElement xmlSection)
{
// loop through the config and initialize the services
// service = createinstance(type)..kind of deal
// m_services.Add(service);
}
public void Start()
{
foreach(ISubService service in m_services) { service.Start(); }
}
public void Stop() { ... }
}
그러면 당신은 단순히, 실제 서비스 코드에서 마지막으로 당신이 당신의 하위 서비스를 위해 필요하지만 많은 threadedservice를 기반으로 클래스를 생성하고, 같은의 app.config에 ... 무언가를 그들 모두를 던져 ..
<me>
<services>
<service type="my.library.service1,my.library" />
<service type="my.library.service2,my.library" />
</services>
</me>
및 ServiceConfiguration.Current.Start()를 시작하고 Exit의 Service.Configuration.Current.Stop()을 수행하면됩니다.
희망 하시겠습니까?
두 개의 별도의 물리적 Windows 서비스 또는 두 가지 기능을 수행하는 Windows 서비스를 찾고 있습니까? – zac
귀하의 Service1/Service2는 어떻게 생겼습니까? 그들은 OnStart 메소드와 ServiceName을 모두 가지고 있습니까? –
@ 앤더스 예. 사실 둘 다 시작하고 개별적으로 잘 실행됩니다. –