GUI + Thread, GUI exits Thread stays -> How to detect thread when GUI starts again?
I'm fairly new to C# so please bear with me. I'm developing a small server application which consists of event driven server thread and a GUI thread. I would like to make GUI and server "independent" (without using two processes). By independent I mean that once GUI starts it checks if server thread is running, if it is not it creates it, otherwise just notifies server thread that GUI thre开发者_JS百科ad is active. And that GUI thread can exit and leave the server thread alive.
Pseudocode:
GUI starts
{
if (serverThread.isRunning)
notify serverThread that GUI is active
else
create and start serverThread
}
GUI exits
{ notify serverThread that GUI is going to be terminated; exit GUI }
The tricky part is how to restart GUI and notify server that GUI is alive.
For now all I do is: start GUI and inside GUI create thread serverThread and start it. After leaving GUI serverThread remains active, but I don't know how to get reference to serverThread when GUI is started again.
GUI is started by clicking on an icon.
Thank you for your time and answers.
I would never want to use such server myself. Combining GUI and server logic into one is always bad idea. Both from design and user viewpoint.
In your case I would recomend creating two separate executables. First would be server and second GUI. Server would possibly be windows service. For communication between the two, WCF would be perfect. It allows you to seamlessly create communication channel on each side without any developer overhead.
I understand your worry about dividing the two. But if you were better and more experienced developer (and possibly an administrator), then you would understand that separating the two is not only logical, but only way to realisticaly solve your problem.
精彩评论