private void NotifySharePriceChange(IUser user) { if (ChangeEvent != null) { Delegate[] invkList = ChangeEvent.GetInvocationList(); //foreach (ChangeDelegate handler in invkList) foreach (var @delegate in invkList) { var handler = (ChangeDelegate)@delegate; var handler1 = handler; new Thread(() => { try { handler1(ChangeOperation.ShareChange, user.IdUser); Debug.WriteLine("Invoking event handler"); } catch (Exception) { ChangeEvent -= handler1; Debug.WriteLine("Exception: Removed an event handler"); } }).Start(); } } SetTimer(); // _myWindow.UpdateView(); }
private void UpdateClients() { if (ChangeEvent != null) { Delegate[] invkList = ChangeEvent.GetInvocationList(); //foreach (ChangeDelegate handler in invkList) foreach (var @delegate in invkList) { var handler = (ChangeDelegate)@delegate; var handler1 = handler; new Thread(() => { try { handler1(ChangeOperation.UpdateInterface, 0); Debug.WriteLine("Invoking event handler"); } catch (Exception) { ChangeEvent -= handler1; Debug.WriteLine("Exception: Removed an event handler"); } }).Start(); } } }
// function that invokes the event in order to warn clients about server changes without creating a deadlock private void SafeInvoke(ChangeArgs args) { if (ChangeEvent != null) { Delegate[] invocationList = ChangeEvent.GetInvocationList(); foreach (ChangeDelegate changeDelegate in invocationList) { try { changeDelegate.BeginInvoke(args, null, null); } catch (Exception) { ChangeEvent -= changeDelegate; } } } }