Open ALiwoto opened 3 years ago
Task.Run
[EditorBrowsable(EditorBrowsableState.Never)] protected internal virtual void OnRightUp() { Task.Run((() => { // raise the event in another thread. this.RightUp?.Invoke(this, null); })); }
So what's wrong with this code?
This will cause some problems in the future, such as hug memory leak.
I think something like this will be okay:
[EditorBrowsable(EditorBrowsableState.Never)] protected internal virtual void OnRightUp() { this.RightUp?.Invoke(this, null); if (this.RightUpAsync != null) { Task.Run((() => { // raise the event in another thread. this.RightUpAsync?.Invoke(this, null); })); } }
This way, we won't create new threads over and over.
Using
Task.Run
is not acceptable everywhereSo what's wrong with this code?
This will cause some problems in the future, such as hug memory leak.
So what to do?
I think something like this will be okay:
This way, we won't create new threads over and over.