I am trying to learn or put together the bits and pieces that I have been picking up so I got a couple of questions:
-
I have a thread that sleeps for 5 hours after it performs its operations, now when that thread sleeps does the application go into an idle state? Does it automatically yield ie or do I have to call thread.Yield()?
-
If you have a wpf application that waits for user input, does it too go into an idle state while it waits? Lets assume that the application might have to wait an entire day before it gets told to do something? What does it do while waiting does it keep consuming resources or simply, automatically, go into an idle state where it waits?
-
Now going from question 2 if the wpf is a self host for a wcf service, what does the wpf do after it has started hosting, does it enter an idle state? So from question 2 the button would be used to reset the service, what would the wpf application do(before you pressed the button, you don’t have to repeat the answer for 2 if its the same)?
Thanks all,
P.S.
Sorry if why question seem real exam like :-S they are not. Just finished exams and that’s all I see :-S
If you call
Thread.Sleep(), the thread won’t use any CPU resources while it’s sleeping. The thread will go into an idle state, the application may consist of multiple threads.The operating system keeps it “asleep” until there is a message ready for it. There is no impact on the CPU while a UI application is running (unless you are using timers on the UI thread or something), however of course it will keep using memory.
The service is hosted from another thread. That thread will not use CPU resources until a message arrives for it. This thread is not visible for you from C# – but if you open the task manager (Ctrl-Alt-Del) while your application is running, you can see the amount of threads running for your application (you might have to add columns to it from the task manager menu bar). Another interesting column is “CPU time” which tells you the impact of your application on the CPU.