public void CallMethod(SynchronizationContext context, BaseDataPackage data) { //Functions[data.GetType()].Invoke(data, default(Guid)); try { //dispatch call into the proper thread context.Post(s => { Functions[data.GetType()].Invoke(data, default(Guid)); }, null); //ConnectionClosed?.Invoke(); } catch (Exception ex) { //dont trust user code Console.WriteLine("Calling client CallMethod data handler threw an exception"); } }