처리되지 않은 예외를 지원하지 않는 멀티 스레드 Windows 서비스 (C#, .NET)를 상속 받았습니다. 이 서비스는 여러 스레드를 사용하여 분석을 위해 원격 측정 장치에서 데이터를 수집합니다. 이 서비스의 스레드는 24 시간 이상 실행할 수 있습니다. 스레드가 문제가 발생하여 재활용해야하는 주 스레드를 알려주는 방법에 어려움을 겪고 있습니다.스레딩 : C#을 사용하여 .NET Windows 서비스의 주 스레드에 콜백
class Program
{
static void Main(string[] args)
{
var workerObject = new WorkerObject();
var workerThread = new Thread(workerObject.DoWork);
workerThread.Start()
}
}
class WorkerObject
{
//todo: My fields and properties go here
public void DoWork()
{
const int timeout = 100;
//todo: setup wait handles here
try
{
//Start monitoring channels for this device
while (true)
{
// Wait on any waithandle or timeout once per decisecond.
int channelIndex = WaitHandle.WaitAny(waitHandles, timeout, false);
//todo: process incoming data for this channel
}
}
//Catch all exceptions so we can notify mommy that we're in a bad way
catch (Exception ex)
{
//todo: log anything that can help us figure this problem out
//How do I tell the main thread I've failed
}
finally
{
//But of course we want to clean up after ourselves
}
}
}
사용이 심지어 최고의 .NET 스레딩 메커니즘은 다음과 같습니다 여기에 코드의 단순화 된보기입니까? Async Delegates 또는 Task Parallel Library를 대신 사용해야합니까?
젠장, 코드에 souce 링크를 추가 할 수 있습니까 ??? 어떤 것을 이해하는 것은 불가능합니다. – IamStalker