public void AddHandler(IDataAddon func) { if (func == null) { return; } comPort.DataReceived -= comPort_DataReceived; _mut.WaitOne(); _AddDataPacketHandlers.Add(func); _mut.ReleaseMutex(); comPort.DataReceived += comPort_DataReceived; }
private void buttonLoad_Click(object sender, EventArgs e) { using (OpenFileDialog dlg = new OpenFileDialog()) { dlg.Title = "Select a file"; dlg.Filter = "Library (*.dll) |*.dll"; if (dlg.ShowDialog() == DialogResult.OK) { Assembly assembly = Assembly.LoadFrom(dlg.FileName); foreach (Type type in assembly.GetTypes()) { IDataAddon addon = Activator.CreateInstance(type) as IDataAddon; if (addon == null) { continue; } _arduinoCircuit.AddHandler(addon); } } } }