File tree Expand file tree Collapse file tree 4 files changed +25
-28
lines changed Expand file tree Collapse file tree 4 files changed +25
-28
lines changed Original file line number Diff line number Diff line change @@ -118,18 +118,6 @@ public virtual bool UpdateLoop()
118
118
return true ;
119
119
}
120
120
121
- if ( Loop == 1 || Loop == 0 )
122
- {
123
- Number = Number + 1 ; //次数增加
124
- CurrentTime = Watch . ElapsedMilliseconds ;
125
- Interval = CurrentTime - Number * Duration ;
126
- Watch . Stop ( ) ;
127
- Watch = null ;
128
- if ( TID != 0 && TimerSystem . TimerExecutors . ContainsKey ( TID ) )
129
- TimerSystem . TimerExecutors . Remove ( TID ) ;
130
- return false ; //达到次数
131
- }
132
-
133
121
if ( Loop == - 1 ) //无限循环
134
122
{
135
123
Number = Number + 1 ; //次数增加
@@ -140,13 +128,16 @@ public virtual bool UpdateLoop()
140
128
return true ;
141
129
}
142
130
143
- if ( Loop == - 2 ) //不执行回调结束
131
+ if ( Loop == 1 || Loop == 0 )
144
132
{
145
- Watch . Stop ( ) ;
146
- Watch = null ;
147
- return false ;
133
+ Number = Number + 1 ; //次数增加
134
+ CurrentTime = Watch . ElapsedMilliseconds ;
135
+ Interval = CurrentTime - Number * Duration ;
148
136
}
149
137
138
+ Watch . Stop ( ) ;
139
+ Watch = null ;
140
+ if ( TID != 0 && TimerSystem . Exist ( TID ) ) TimerSystem . Pop ( TID ) ;
150
141
return false ;
151
142
}
152
143
@@ -157,10 +148,7 @@ public int CompareTo(ITimerExecutor other)
157
148
return 0 ;
158
149
}
159
150
160
- public void Dispose ( )
161
- {
162
- Delegates = null ;
163
- }
151
+ public void Dispose ( ) { Delegates = null ; }
164
152
165
153
public sealed override string ToString ( )
166
154
{
@@ -192,4 +180,4 @@ public void Execute()
192
180
193
181
protected abstract void xExecute ( ) ;
194
182
}
195
- }
183
+ }
Original file line number Diff line number Diff line change @@ -103,4 +103,4 @@ public override void OtherUpdate(long nowTime)
103
103
}
104
104
}
105
105
}
106
- }
106
+ }
Original file line number Diff line number Diff line change 1
1
#region
2
2
3
3
using System ;
4
+ using System . Collections . Generic ;
4
5
5
6
#endregion
6
7
@@ -21,6 +22,14 @@ partial class TimerSystem
21
22
/// <summary>
22
23
/// 判断任务是否存在
23
24
/// </summary>
24
- public static bool Exist < E > ( E key ) where E : Enum { return TimerExecutors . ContainsKey ( key . GetHashCode ( ) ) ; }
25
+ public static bool Exist < E > ( E key )
26
+ where E : Enum => TimerExecutors . ContainsKey ( key . GetHashCode ( ) ) ;
27
+
28
+ public static ITimerExecutor Get ( long key ) { return TimerExecutors . GetValueOrDefault ( key , null ) ; }
29
+
30
+ public static ITimerExecutor Get ( string key ) { return TimerExecutors . GetValueOrDefault ( key . GetHashCode ( ) , null ) ; }
31
+
32
+ public static ITimerExecutor Get < E > ( E key )
33
+ where E : Enum => TimerExecutors . GetValueOrDefault ( key . GetHashCode ( ) , null ) ;
25
34
}
26
- }
35
+ }
Original file line number Diff line number Diff line change @@ -15,9 +15,8 @@ partial class TimerSystem
15
15
/// <param name="key"> 任务ID </param>
16
16
public static void Pop ( long key )
17
17
{
18
- if ( ! TimerExecutors . TryGetValue ( key , out var executor ) ) return ;
18
+ if ( ! TimerExecutors . Remove ( key , out var executor ) ) return ;
19
19
executor . Loop = - 2 ;
20
- TimerExecutors . Remove ( key ) ;
21
20
}
22
21
23
22
/// <summary>
@@ -34,6 +33,7 @@ public static void Pop(string key)
34
33
/// 取出循环任务
35
34
/// </summary>
36
35
/// <param name="key"> 任务ID </param>
37
- public static void Pop < E > ( E key ) where E : Enum { Pop ( key . GetHashCode ( ) ) ; }
36
+ public static void Pop < E > ( E key )
37
+ where E : Enum => Pop ( key . GetHashCode ( ) ) ;
38
38
}
39
- }
39
+ }
You can’t perform that action at this time.
0 commit comments