Warmup() public method

Warmups the specified type by calling all the methods for the specified type.
The is null.
public Warmup ( Type type ) : void
type System.Type The type.
return void
コード例 #1
0
        /// <summary>
        /// Warms up the specified types. If the <paramref name="types" /> is <c>null</c>, all types known
        /// in the <see cref="TypeCache" /> will be initialized.
        /// <para />
        /// Note that it is not required to call this, but it can help to prevent an additional performance
        /// impact the first time a type is serialized.
        /// </summary>
        /// <param name="types">The types to warmp up. If <c>null</c>, all types will be initialized.</param>
        /// <param name="typesPerThread">The types per thread. If <c>-1</c>, all types will be initialized on the same thread.</param>
        public void Warmup(IEnumerable <Type> types, int typesPerThread = 1000)
        {
            ApiCop.UpdateRule <InitializationApiCopRule>("SerializerBase.WarmupAtStartup",
                                                         x => x.SetInitializationMode(InitializationMode.Eager, GetType().GetSafeFullName(false)));

            if (types == null)
            {
                types = TypeCache.GetTypes(x => x.IsModelBase(), false);
            }

            var allTypes = new List <Type>(types);

            ParallelHelper.ExecuteInParallel(allTypes, type =>
            {
                // General warmup
                SerializationManager.Warmup(type);

                // Specific (customized) warmup
                Warmup(type);
            }, typesPerThread, "warmup serializer for types");
        }