Home > Net >  C # program is turned off, background process is still there, could also not end in the task manager
C # program is turned off, background process is still there, could also not end in the task manager

Time:09-21

C # winform program is closed, but the background process is still there, I saw on the net, have threads run in the background, the relationship between program, I use the timer to polling in a state of order, every time when polling and then use the task to control the timeout, the relationship between the task?
Boolean ret=false;
The Task of Task=new Task (()=& gt;
{
Result=getOrderStatus (SHZDH ZDSJ);
Ret=true;
});

DateTime beginTime=DateTime. Now;

Task. Start ();


While ((DateTime. Now - beginTime). TotalSeconds & lt;=10.0)//time stretched to ten seconds, in some cases longer query order
{
If (ret)
{
return result;
}

Thread.sleep (500);
}

Return the invalid;
  •  Tags:  
  • C#
  • Related