Exemplo n.º 1
0
            [MethodImpl(MethodImplOptions.AggressiveInlining)] // avoid long-lived stack frame in many threads
            private void RunWorker()
            {
                InitializeCulture();

                Delegate start = _start;

                _start = null !;

#if FEATURE_OBJCMARSHAL
                if (AutoreleasePool.EnableAutoreleasePool)
                {
                    AutoreleasePool.CreateAutoreleasePool();
                }
#endif

                if (start is ThreadStart threadStart)
                {
                    threadStart();
                }
                else
                {
                    ParameterizedThreadStart parameterizedThreadStart = (ParameterizedThreadStart)start;

                    object?startArg = _startArg;
                    _startArg = null;

                    parameterizedThreadStart(startArg);
                }

#if FEATURE_OBJCMARSHAL
                // There is no need to wrap this "clean up" code in a finally block since
                // if an exception is thrown above, the process is going to terminate.
                // Optimize for the most common case - no exceptions escape a thread.
                if (AutoreleasePool.EnableAutoreleasePool)
                {
                    AutoreleasePool.DrainAutoreleasePool();
                }
#endif
            }