Summary description for GarbageCollection.
Example #1
0
        static void Main(string[] args)
        {
            if (!ProcessArguments(args))
            {
                return;
            }

            // Initialize critical member variables.
            m_iObjsInUse     = 0;
            m_iServerLocks   = 0;
            m_uiMainThreadId = GetCurrentThreadId();

            // Register the SimpleCOMObjectClassFactory.
            SimpleCOMObjectClassFactory factory = new SimpleCOMObjectClassFactory();

            factory.ClassContext = (uint)CLSCTX.CLSCTX_LOCAL_SERVER;
            factory.ClassId      = Marshal.GenerateGuidForType(typeof(XApiCom));
            factory.Flags        = (uint)REGCLS.REGCLS_MULTIPLEUSE | (uint)REGCLS.REGCLS_SUSPENDED;
            factory.RegisterClassObject();
            ClassFactoryBase.ResumeClassObjects();

            // Start up the garbage collection thread.
            GarbageCollection GarbageCollector        = new GarbageCollection(10000);
            Thread            GarbageCollectionThread = new Thread(new ThreadStart(GarbageCollector.GCWatch));

            // Set the name of the thread object.
            GarbageCollectionThread.Name = "Garbage Collection Thread";
            // Start the thread.
            GarbageCollectionThread.Start();

            // Start the message loop.
            MSG    msg;
            IntPtr null_hwnd = new IntPtr(0);

            while (GetMessage(out msg, null_hwnd, 0, 0) != false)
            {
                TranslateMessage(ref msg);
                DispatchMessage(ref msg);
            }
            Console.WriteLine("Out of message loop.");

            // Revoke the class factory immediately.
            // Don't wait until the thread has stopped before
            // we perform revokation.
            factory.RevokeClassObject();
            Console.WriteLine("SimpleCOMObjectClassFactory Revoked.");

            // Now stop the Garbage Collector thread.
            GarbageCollector.StopThread();
            GarbageCollector.WaitForThreadToStop();
            Console.WriteLine("GarbageCollector thread stopped.");

            // Just an indication that this COM EXE Server is stopped.
            Console.WriteLine("Press [ENTER] to exit.");
            Console.ReadLine();
        }
Example #2
0
        static void Main(string[] args)
        {
            if (!ProcessArguments(args))
            {
                return;
            }

            // Initialize critical member variables.
            m_iObjsInUse = 0;
            m_iServerLocks = 0;
            m_uiMainThreadId = GetCurrentThreadId();

            // Register the SimpleCOMObjectClassFactory.
            SimpleCOMObjectClassFactory factory = new SimpleCOMObjectClassFactory();
            factory.ClassContext = (uint)CLSCTX.CLSCTX_LOCAL_SERVER;
            factory.ClassId = Marshal.GenerateGuidForType(typeof(XApiCom));
            factory.Flags = (uint)REGCLS.REGCLS_MULTIPLEUSE | (uint)REGCLS.REGCLS_SUSPENDED;
            factory.RegisterClassObject();
            ClassFactoryBase.ResumeClassObjects();

            // Start up the garbage collection thread.
            GarbageCollection	GarbageCollector = new GarbageCollection(10000);
            Thread				GarbageCollectionThread = new Thread(new ThreadStart(GarbageCollector.GCWatch));

            // Set the name of the thread object.
            GarbageCollectionThread.Name = "Garbage Collection Thread";
            // Start the thread.
            GarbageCollectionThread.Start();

            // Start the message loop.
            MSG			msg;
            IntPtr		null_hwnd = new IntPtr(0);
            while (GetMessage(out msg, null_hwnd, 0, 0) != false)
            {
                TranslateMessage(ref msg);
                DispatchMessage(ref msg);
            }
            Console.WriteLine("Out of message loop.");

            // Revoke the class factory immediately.
            // Don't wait until the thread has stopped before
            // we perform revokation.
            factory.RevokeClassObject();
            Console.WriteLine("SimpleCOMObjectClassFactory Revoked.");

            // Now stop the Garbage Collector thread.
            GarbageCollector.StopThread();
            GarbageCollector.WaitForThreadToStop();
            Console.WriteLine("GarbageCollector thread stopped.");

            // Just an indication that this COM EXE Server is stopped.
            Console.WriteLine("Press [ENTER] to exit.");
            Console.ReadLine();
        }