How to keep thread alive throughout the windows application c# -


I am using thread which will receive messages from external application. That's why my thread will always be alive.

I want my thread to run through the application, unless the application is exhausted. Currently I'm calling my thread in program.cs, which is a startup for windows application c. Please see the code below to learn how I am doing it.

When I use the code below, the thread starts when the program starts ... but how it closes, the external application after receiving the thread from a message.

I hope that I am clear with my questio please help. Thank you.


  Fixed zero main () {Application.EnableVisualStyles (); Application.SetCompatibleTextRenderingDefault (wrong); StartThread (); Application Run (new screensaver ()); } Public static zero start thread () {DeamonEngine Deamon = New DeamonEngine (); Thread thread receiver = new thread (daemon. Receiver); If (ThreadReciever.IsAlive) {ThreadReciever.Start (); }}}  

From a comment:

  zero recipient (try {try {start socket; Tie IP address; S.Receiver [bytes]; Access to members of messages received in bytes; Specify the members of the message in the local variable; Read the XML file, get the node value and write it in the batch file; Execute the batch file. } Hold {}}  

does not mean having a thread executing the receiver method The thread will execute the system repeatedly.

Looking at the processing code in question, daemon. The receiver needs to be executed in the loop so that it can go back and retrieve the next message process. It should look like this:

  zero recipient () {while (done!) // Without this loop, only one execution will be {try {// do stuff} catch {// Log / handle error} // wait for next message}}  

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -