Repository: godotengine/godot
File: modules/mono/glue/GodotSharp/GodotSharp/Core/GodotTaskScheduler.cs (C#)

Code before:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Godot
{
    public class GodotTaskScheduler : TaskScheduler
    {
        internal GodotSynchronizationContext Context { get; }
        private readonly LinkedList<Task> _tasks = new LinkedList<Task>();

        public GodotTaskScheduler()
        {
            Context = new GodotSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(Context);
        }

        protected sealed override void QueueTask(Task task)
        {
            lock (_tasks)
            {
                _tasks.AddLast(task);
            }
        }

        protected sealed override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
        {
            if (SynchronizationContext.Current != Context)
                return false;

            if (taskWasPreviouslyQueued)
                TryDequeue(task);

            return TryExecuteTask(task);
        }

        protected sealed override bool TryDequeue(Task task)
        {
            lock (_tasks)
            {
                return _tasks.Remove(task);
            }
        }

        protected sealed override IEnumerable<Task> GetScheduledTasks()
        {
            lock (_tasks)
            {
                foreach (Task task in _tasks)

Review comment (suggestion):
I think we can improve upon what you have here. Something like this:

```suggestion
        /// Constructs a new GodotTaskScheduler instance.
```

Code after:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

namespace Godot
{
    /// <summary>
    /// GodotTaskScheduler contains a linked list of tasks to perform as a queue. Methods
    /// within the class are used to control the queue and perform the contained tasks.
    /// </summary>
    public class GodotTaskScheduler : TaskScheduler
    {
        /// <summary>
        /// The current synchronization context.
        /// </summary>
        internal GodotSynchronizationContext Context { get; }

        /// <summary>
        /// The queue of tasks for the task scheduler.
        /// </summary>
        private readonly LinkedList<Task> _tasks = new LinkedList<Task>();

        /// <summary>
        /// Constructs a new GodotTaskScheduler instance.
        /// </summary>
        public GodotTaskScheduler()
        {
            Context = new GodotSynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(Context);
        }

        protected sealed override void QueueTask(Task task)
        {
            lock (_tasks)
            {
                _tasks.AddLast(task);
            }
        }

        protected sealed override bool TryExecuteTaskInline(Task task, bool taskWasPreviouslyQueued)
        {
            if (SynchronizationContext.Current != Context)
                return false;

            if (taskWasPreviouslyQueued)
                TryDequeue(task);

            return TryExecuteTask(task);
        }