99using System . Threading ;
1010using System . Threading . Tasks ;
1111using NLog ;
12+ using ProtoBuf . Meta ;
1213using Sandbox ;
1314using Sandbox . Engine . Multiplayer ;
1415using Sandbox . Game ;
@@ -191,16 +192,18 @@ public Task SaveGameAsync(Action<SaveGameStatus> callback)
191192 /// Invokes an action on the game thread.
192193 /// </summary>
193194 /// <param name="action"></param>
194- public void Invoke ( Action action )
195+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
196+ public void Invoke ( Action action , [ CallerMemberName ] string caller = "" )
195197 {
196- MySandboxGame . Static . Invoke ( action , "Torch" ) ;
198+ MySandboxGame . Static . Invoke ( action , caller ) ;
197199 }
198200
199201 /// <summary>
200202 /// Invokes an action on the game thread asynchronously.
201203 /// </summary>
202204 /// <param name="action"></param>
203- public Task InvokeAsync ( Action action )
205+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
206+ public Task InvokeAsync ( Action action , [ CallerMemberName ] string caller = "" )
204207 {
205208 if ( Thread . CurrentThread == MySandboxGame . Static . UpdateThread )
206209 {
@@ -209,14 +212,15 @@ public Task InvokeAsync(Action action)
209212 return Task . CompletedTask ;
210213 }
211214
212- return Task . Run ( ( ) => InvokeBlocking ( action ) ) ;
215+ return Task . Run ( ( ) => InvokeBlocking ( action , caller ) ) ;
213216 }
214217
215218 /// <summary>
216219 /// Invokes an action on the game thread and blocks until it is completed.
217220 /// </summary>
218221 /// <param name="action"></param>
219- public void InvokeBlocking ( Action action )
222+ [ MethodImpl ( MethodImplOptions . NoInlining ) ]
223+ public void InvokeBlocking ( Action action , [ CallerMemberName ] string caller = "" )
220224 {
221225 if ( action == null )
222226 return ;
@@ -240,7 +244,7 @@ public void InvokeBlocking(Action action)
240244 {
241245 e . Set ( ) ;
242246 }
243- } , "Torch" ) ;
247+ } , caller ) ;
244248
245249 if ( ! e . WaitOne ( 60000 ) )
246250 throw new TimeoutException ( "The game action timed out." ) ;
0 commit comments