jakesee / ganttchart

The Winforms Gantt Chart is the .NET Winforms control originally hosted on CodePlex (http://ganttchart.codeplex.com)
https://jakesee.sg/net-c-winforms-gantt-chart-control/
MIT License
178 stars 78 forks source link

Make event firing thread-safe #4

Open jakesee opened 7 years ago

jakesee commented 7 years ago

Hi, Possibly a minor point, but the event firing could be more thread-safe by copying the handler to a local variable and then firing the local variable. This prevents potential issues where while the task is firing a separate thread adds or removes more handlers before the event is complete. It's an edge case, but as nobody can know how this control may be used anything is possible. For example, OnTaskMouseDoubleClick would look like:

private void OnTaskMouseDoubleClick(TaskMouseEventArgs e)
{
    EventHandler<TaskMouseEventArgs> locum = TaskMouseDoubleClick;
    if(locum != null)
    {
        locum(this, e);
    }
}