我正在使用線程,它將接收來自 外部應用程序的消息。所以我的線程總是處於活動狀態。如何保持線程在整個Windows應用程序中活着c#
我想讓我的線程運行完整個應用程序,直到 直到應用程序退出。目前我在program.cs中調用我的線程, 這是windows應用程序c#的啓動。請參閱下面的代碼 知道我是如何做到這一點。
當我使用下面的代碼時,線程在 應用程序啓動時啓動...但它會中斷一些如何在線程接收到來自外部應用程序的一條消息之後 。
我希望我對我的問題很清楚。請幫忙。謝謝。
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 { }
}
Karthik,幾次你說有一個循環。你能告訴我們這個循環嗎?我沒看到一個。您發佈的代碼將執行一次,然後線程將終止。 – 2009-07-25 20:47:35