Exemplo n.º 1
0
        protected override void ExecuteInternal()
        {
            var testDomain          = AppDomain.CreateDomain("TestAppDomain");
            var crossDomainInstance = (CrossDomainObject)testDomain.CreateInstanceAndUnwrap(typeof(CrossDomainObject).Assembly.FullName, typeof(CrossDomainObject).FullName);

            crossDomainInstance.WriteCurrentDomain();

            Console.Green("Cross domain instance created");
            Debugger.Break();
            AppDomain.Unload(testDomain);
        }
Exemplo n.º 2
0
        private void LeakedThreads()
        {
            var threads = Enumerable.Range(1, 10)
                          .Select(i =>
            {
                var t  = new Thread(_ => Console.Green($"I Am Thread #{Thread.CurrentThread.ManagedThreadId}"));
                t.Name = $"TestThread #{i}";
                t.Start();
                t.Join();

                return(t);
            });

            _threads.AddRange(threads);
        }
        protected override void ExecuteInternal()
        {
            ThreadPool.QueueUserWorkItem(_ =>
            {
                Thread.Sleep(Timeout.Infinite);
            });
            ThreadPool.QueueUserWorkItem(_ =>
            {
                Thread.Sleep(Timeout.Infinite);
            });

            Thread CreateDeadlockedThread(EventWaitHandle ewh1, EventWaitHandle ewh2)
            {
                var thread = new Thread(_ =>
                {
                    try
                    {
                        lock (ewh1)
                        {
                            WaitHandle.SignalAndWait(ewh1, ewh2);
                            Console.Green($"Thread {Thread.CurrentThread.ManagedThreadId} has aquired first lock");

                            lock (ewh2)
                            {
                                System.Console.WriteLine("We will never see this string");
                            }
                        }
                    }
                    catch (ThreadInterruptedException) { }
                });

                return(thread);
            }

            var are1 = new EventWaitHandle(false, EventResetMode.AutoReset);
            var are2 = new EventWaitHandle(false, EventResetMode.AutoReset);

            var thread1 = CreateDeadlockedThread(are1, are2);
            var thread2 = CreateDeadlockedThread(are2, are1);

            thread1.Start();
            thread2.Start();

            Console.WaitForContinue("Interrupt both threads");
            thread1.Interrupt();
            thread2.Interrupt();
        }
Exemplo n.º 4
0
        protected override void ExecuteInternal()
        {
            LeakedAttachedClass();

            Debugger.Break();

            var leakedPointerAddresses = LeakedPointers();

            CollectWithFinalizers();
            Console.WaitForContinue("Release leaked resources (sic!)");
            ReleaseLeakedResources(leakedPointerAddresses);
            CollectWithFinalizers();
            Console.WaitForContinue("Resources has been released");

            LeakedThreads();
            CollectWithFinalizers();
            Console.WaitForContinue("Threads has been created");
        }
Exemplo n.º 5
0
 public void WriteCurrentDomain()
 {
     Console.Green($"Current AppDomain name: {AppDomain.CurrentDomain.FriendlyName}");
 }