public void CallbackToSyncContext() { var path = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name; var binding = new NetNamedPipeBinding(NetNamedPipeSecurityMode.None) { MaxConnections = 5 }; using (var server = new ServiceHost(new SyncCallbackService(), new Uri(path))) { server.AddServiceEndpoint(typeof(ISyncCallbackService), binding, path); server.Open(); using (var syncContext = new StaSynchronizationContext()) { InstanceContext context = null; DuplexChannelFactory <ISyncCallbackService> channelFactory = null; ISyncCallbackService client = null; syncContext.Send(_ => SynchronizationContext.SetSynchronizationContext(syncContext), null); syncContext.Send(_ => context = new InstanceContext(new SyncCallbackServiceCallback()), null); syncContext.Send(_ => channelFactory = new DuplexChannelFactory <ISyncCallbackService>(context, binding), null); syncContext.Send(_ => client = channelFactory.CreateChannel(new EndpointAddress(path)), null); using (channelFactory) { var callbackThread = client.Call(); Assert.AreEqual(syncContext.ManagedThreadId, callbackThread); } } } }
public static void DisposeModule() { _staContext.Dispose(); _staContext = null; Service.Dispose(); Service = null; }
private void btnStaSynchronizationContext_Click(object sender, EventArgs e) { mStaSyncContext = new StaSynchronizationContext(); for (int i = 0; i < 100; i++) { ThreadPool.QueueUserWorkItem(NonStaThread); } Console.WriteLine("Processing"); Console.WriteLine("Press any key to dispose SyncContext"); Console.ReadLine(); mStaSyncContext.Dispose(); }
public void Dispose() { syncContext.Dispose(); syncContext = null; }
public TestWindowManager() { syncContext = new StaSynchronizationContext(); }
protected virtual void TearDown() { syncContext.Dispose(); syncContext = null; Monitor.Exit(LockObj); }
protected virtual void Setup() { Monitor.Enter(LockObj); syncContext = new StaSynchronizationContext(); }
static RecorderModule() { Service = new TService(); _staContext = new StaSynchronizationContext("Recorder"); }