Windows 서비스에서 Rx 확장 프로그램을 사용하려고하는데 막혔습니다. 내가 찾은 샘플은 작동하지 않습니다. 나는 어떤 코드로 내가 성취하고자하는 것을 설명 할 것이다.Windows 서비스에서 Rx 사용
class Worker : IDisposable {
public Worker() {
}
private void Run() {
}
public void Dispose() {
}
}
내가 ONSTART의 인스턴스를 생성하고 그것을를 OnStop 죽이고 싶어 :
public partial class MyService : ServiceBase {
private Worker _Worker;
public MyService() {
InitializeComponent();
}
protected override void OnStart (string[] args) {
_Worker = new Worker();
}
protected override void OnStop() {
_Worker.Dispose();
_Worker = null;
}
}
그래서 내가이 일에 가서 내가 만드는거야 맨 처음 클래스는 실제로 모든 작업을 수행하는 클래스입니다 Worker의 생성자에서 :
/* _TimesEvents and _Events are class level variables */
_TimedEvents = Observable.Timer (TimeSpan.FromSeconds (1), new EventLoopScheduler()).Timestamp();
_Events = (from events in _TimedEvents select events).Subscribe (e => Run());
Dispose에서 나는 방금 _Events를 삭제했습니다. 실행은 한 번 호출됩니다. 매 초마다 불리는 것 같아요.
무엇이 누락 되었습니까?
편집 :
내 Main()
은 다음과 같습니다 테스트하려면 : TimeSpan
가 완료된 후
static void Main () {
var args = Environment.GetCommandLineArgs();
if (null != args && args.Length > 0) {
using (BRWorker worker = new BRWorker() ) {
System.Windows.Forms.MessageBox.Show ("Press ok to quit", "Test", System.Windows.Forms.MessageBoxButtons.OK);
}
} else {
ServiceBase[] ServicesToRun;
ServicesToRun = new ServiceBase[]
{
new BRService()
};
ServiceBase.Run (ServicesToRun);
}
}
고마워. 나는 간단한 해결책 인 복잡한 해결책을 찾았다. ... – Sascha
나는 똑같은 일을하려하고있다. Service 클래스에서 어디로 가는지 보여주는 샘플을 게시하거나 링크 할 수 있습니까? –