Add notes regarding using inline delegates with Scheduler.AddOnce

This commit is contained in:
Dean Herbert
2023-10-10 22:28:58 +09:00
parent 238fa682a4
commit 5fd6cf5896
2 changed files with 3 additions and 1 deletions

View File

@@ -429,6 +429,8 @@ namespace osu.Framework.Tests.Threading
{
classInvocations = 0;
// Note that while this works here (even with a capture), there's no guarantee that will always be the
// case. As such it's always best to use a local function or private method.
for (int i = 0; i < 10; i++)
invokeInlineDelegateAction();

View File

@@ -368,7 +368,7 @@ namespace osu.Framework.Threading
/// Adds a task which will only be run once per frame, no matter how many times it was scheduled in the previous frame.
/// </summary>
/// <remarks>The task will be run on the next <see cref="Update"/> independent of the current clock time.</remarks>
/// <param name="task">The work to be done.</param>
/// <param name="task">The work to be done. Avoid using inline delegates as they may not be cached, bypassing the once-per-frame guarantee.</param>
/// <returns>Whether this is the first queue attempt of this work.</returns>
public bool AddOnce(Action task)
{