代码
1
public
static
int
count
=
0
;
2 public static int total = 0 ;
3 public static Timer timer1;
4 public static Timer timer2;
5 public static Random ranobj;
6 public static int timevalue;
7 public static int a;
8 public static int A = 0 ;
9 public static void Main()
10 {
11 ranobj = new Random();
12
13 a = ranobj.Next( 3 , 5 );
14 total = ranobj.Next( 4 , 6 );
15 timevalue = (a * 60 ) / total;
16 timer1 = new Timer( new TimerCallback(CheckStatus), null , 0 , timevalue * 1000 );
17
18 Console.ReadLine();
19 }
20
21
22 static void CheckStatus(Object state)
23 {
24
25 if (count < total)
26 {
27 count ++ ;
28 A ++ ;
29
30 }
31 else
32 {
33 count = 0 ;
34 timer1.Dispose();
35 total = ranobj.Next( 5 , 15 );
36 timevalue = (a * 60 ) / total;
37 timer2 = new Timer( new TimerCallback(CheckStatus2), null , 0 , timevalue * 1000 );
38 }
39
40 }
41
42 static void CheckStatus2(Object state)
43 {
44
45 if (count < total)
46 {
47 count ++ ;
48 A -- ;
49
50 }
51 else
52 {
53 count = 0 ;
54 timer2.Dispose();
55 }
56
57 }
2 public static int total = 0 ;
3 public static Timer timer1;
4 public static Timer timer2;
5 public static Random ranobj;
6 public static int timevalue;
7 public static int a;
8 public static int A = 0 ;
9 public static void Main()
10 {
11 ranobj = new Random();
12
13 a = ranobj.Next( 3 , 5 );
14 total = ranobj.Next( 4 , 6 );
15 timevalue = (a * 60 ) / total;
16 timer1 = new Timer( new TimerCallback(CheckStatus), null , 0 , timevalue * 1000 );
17
18 Console.ReadLine();
19 }
20
21
22 static void CheckStatus(Object state)
23 {
24
25 if (count < total)
26 {
27 count ++ ;
28 A ++ ;
29
30 }
31 else
32 {
33 count = 0 ;
34 timer1.Dispose();
35 total = ranobj.Next( 5 , 15 );
36 timevalue = (a * 60 ) / total;
37 timer2 = new Timer( new TimerCallback(CheckStatus2), null , 0 , timevalue * 1000 );
38 }
39
40 }
41
42 static void CheckStatus2(Object state)
43 {
44
45 if (count < total)
46 {
47 count ++ ;
48 A -- ;
49
50 }
51 else
52 {
53 count = 0 ;
54 timer2.Dispose();
55 }
56
57 }