Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 0.65 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. ## Test
  2. [TestMethod()]
  3. public void ThreadSingletonShouldBecollectedwhenThreadFinished()
  4. {
  5.         var builder = new ContainerBuilder();                  
  6.         builder.Register<IDo, Do>().ControlledBy<ThreadSingletonLifecycle>();
  7.         var container = builder.Build();
  8.         WeakReference obj = null; ;
  9.         Action action = () =>
  10.         {
  11.                 var o = container.Resolve<IDo>();
  12.                 obj = new WeakReference(o);
  13.         };
  14.  
  15.         var thread = new Thread(new ThreadStart(action));
  16.         thread.Start();
  17.         thread.Join();
  18.         Assert.IsTrue(obj.IsAlive);
  19.         thread = null;
  20.         GC.Collect(2);
  21.         Assert.IsFalse(obj.IsAlive, "Objekt sollte nicht mehr existieren");            
  22. }
  23.  
  24. ## interfaces
  25. public interface IDo{}
  26.  
  27. public class Do : IDo{}