コード例 #1
0
        public async Task <Trivia> Create(int count = 1)
        {
            IFetchingService fetcher;
            Trivia           trivia = new Trivia();

            if (_source == Source.Wiki)
            {
                fetcher = new WikiFetchingService();
            }
            else if (_source == Source.Meme)
            {
                fetcher = new MemepediaFetchingService();
            }

            else if (_source == Source.Any)
            {
                var wikiFetcher = new WikiFetchingService();
                var memeFether  = new MemepediaFetchingService();

                trivia = new Trivia();

                for (int i = 0; i < count; i += 2)
                {
                    GC.AddMemoryPressure(300000);
                    var question = await memeFether.GetRandomQuestion();

                    trivia.Add(question);
                    GC.RemoveMemoryPressure(300000);
                    GC.Collect();
                    GC.WaitForPendingFinalizers();
                }
                for (int i = 1; i < count; i += 2)
                {
                    var question = await wikiFetcher.GetRandomQuestion();

                    trivia.Add(question);
                }

                return(trivia);
            }

            else
            {
                throw new NotSupportedException($"Source {_source} is not supported");
            }

            for (int i = 0; i < count; i++)
            {
                GC.AddMemoryPressure(300000);
                var question = await fetcher.GetRandomQuestion();

                trivia.Add(question);
                GC.RemoveMemoryPressure(300000);
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
            return(trivia);
        }
コード例 #2
0
ファイル: CssParser.cs プロジェクト: carbon/Css
        public Trivia ReadTrivia()
        {
            if (isEnd || !current.IsTrivia) return null;

            var trivia = new Trivia();

            while (current.IsTrivia && !isEnd)
            {
                trivia.Add(Read());
            }

            return trivia;
        }