【发布时间】:2009-06-25 04:57:30
【问题描述】:
我正在使用线程,它将接收来自 外部应用程序。所以我的线程应该永远活着。
我希望我的线程在整个应用程序中运行, 直到应用程序退出。目前我在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,你多次说过有一个循环。你能给我们看看循环吗?我没有看到一个。您发布的代码将执行一次,然后线程将终止。
标签: c# windows desktop-application