public void AttachOnlyOneHandler(Func <string, string> handler) { lock (someEventLock) { if (FormatterEvent != null) { foreach (var del in FormatterEvent.GetInvocationList()) { FormatterEvent -= (Func <string, string>)del; } } FormatterEvent += handler; } }
public void OnSmsReceived(string msg) { lock (someEventLock) { if (MessageBox.InvokeRequired == true) { this?.BeginInvoke(new SmsProvider.SMSReceivedDelegate(OnSmsReceived), msg); } else { msg = FormatterEvent?.Invoke(msg) ?? msg; MessageBox.Invoke(new Action(() => MessageBox.AppendText($"{msg}{Environment.NewLine}"))); } } }