Quantcast
Channel: Rhino Developer - McNeel Forum
Viewing all articles
Browse latest Browse all 8527

AddRhinoObject raised twice when event handler references class param

$
0
0

@Jon wrote:

Apologies if this is a basic programming question. Typically when moving an object in Rhino, the AddRhinoObject event is raised once. However, if I reference a class field inside the event handler, the event is raised twice (see below). How can I prevent this from happening?

    internal class RhinoListenerClass
    {
        private Task listener;
        private List<double> data;

        internal RhinoListenerClass()
        {
            data = new List<double>();
            listener = RhinoListener();
        }

        private async Task RhinoListener()
        {
            await Task.Run(() =>
            {
                RhinoDoc.AddRhinoObject += (s, e) =>
                {
                    Eto.Forms.MessageBox.Show("AddRhinoObject");
                    var d = data; // this causes the event to be raised twice
                };
            });
        }
    }

Thanks :slight_smile:

Jon

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 8527

Trending Articles