外部アプリケーションからメッセージを受信するスレッドを使用しています。そのため、スレッドは常に生きています。
アプリケーションが終了するまで、スレッドをアプリケーション全体で実行したいと考えています。現在、windows アプリケーション c# のスタートアップである program.cs で自分のスレッドを呼び出しています。私がそれをどのように行っているかを知るには、以下のコードを参照してください。
以下のコードを使用すると、アプリケーションの起動時にスレッドが起動します...しかし、スレッドが外部アプリケーションから1つのメッセージを受信した後、何らかの方法で中止されます。
私の質問が明確であることを願っています。助けてください。ありがとう。
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
StartThread();
Application.Run(new Screensaver());
}
public static void StartThread()
{
DeamonEngine Deamon = new DeamonEngine();
Thread ThreadReciever = new Thread(Deamon.Receiver);
if (!(ThreadReciever.IsAlive))
{
ThreadReciever.Start();
}
}
}
コメントから:
void Receiver() {
try {
Initiate socket s;
Bind Ip address;
s.Receiver[bytes];
Access the members of message received in bytes;
Assign the members of message to local variable;
Read Xml File, get the node values and write to batch file;
Execute batch file.
}
catch { }
}