private void TestClient() { SynchronizationContext context = SynchronizationContext.Current; //Have to test client on another thread, otherwise there is a deadlock b/c the service is hosted on the main thread. ThreadPool.QueueUserWorkItem(delegate { try { using (ViewerAutomationServiceClient client = new ViewerAutomationServiceClient()) { client.GetActiveViewers(); } context.Post(delegate { base.Context.DesktopWindow.ShowMessageBox("Success!", MessageBoxActions.Ok); }, null); } catch (Exception e) { context.Post(delegate { base.Context.DesktopWindow.ShowMessageBox(e.Message, MessageBoxActions.Ok); }, null); } }); }
public GetActiveViewersResult GetActiveViewers() { // Done for reasons of speed, as well as the fact that a call to the service from the same thread // that the service is hosted on (the main UI thread) will cause a deadlock. if (SynchronizationContext.Current == ViewerAutomationServiceHostTool.HostSynchronizationContext) { return new ViewerAutomation().GetActiveViewers(); } else { using (ViewerAutomationServiceClient client = new ViewerAutomationServiceClient()) { return client.GetActiveViewers(); } } }
public GetActiveViewersResult GetActiveViewers() { // Done for reasons of speed, as well as the fact that a call to the service from the same thread // that the service is hosted on (the main UI thread) will cause a deadlock. if (SynchronizationContext.Current == ViewerAutomationServiceHostTool.HostSynchronizationContext) { return(new ViewerAutomation().GetActiveViewers()); } else { using (ViewerAutomationServiceClient client = new ViewerAutomationServiceClient()) { return(client.GetActiveViewers()); } } }