未処理の例外をサポートしないマルチスレッド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