C#数据等待

时间:2023-01-25 05:41:09
 1  public bool WaitData()
2 {
3 bool states = false;
4 try
5 {
6 DateTime Get_Time = DateTime.Now;
7 while (!DeviceStates)
8 {
9 Thread.Sleep(10);
10 if (DeviceStates == true)
11 {
12 states = true;
13 return states;
14 }
15
16 TimeSpan P_TimeSpan = DateTime.Now - Get_Time;
17 if (P_TimeSpan.Seconds >= 1)
18 {
19 states = false;
20 return states;
21 }
22 }
23 return states;
24 }
25 catch (Exception ex)
26 {
29 return states;
30 }
      
}