当前位置: 首页>>代码示例>>C#>>正文


C# TemplateService.Dispose方法代码示例

本文整理汇总了C#中TemplateService.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# TemplateService.Dispose方法的具体用法?C# TemplateService.Dispose怎么用?C# TemplateService.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TemplateService的用法示例。


在下文中一共展示了TemplateService.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TemplateService_CanParseTemplatesInParallel_WithThreadPool

        public void TemplateService_CanParseTemplatesInParallel_WithThreadPool()
        {
            var service = new TemplateService();

            const int count = 10;
            const string template = "<h1>Hello you are @Model.Age</h1>";

            /* As we are leaving the threading to the pool, we need a way of coordinating the execution
             * of the test after the threadpool has done its work. ManualResetEvent instances are the way. */
            var resetEvents = new ManualResetEvent[count];
            for (int i = 0; i < count; i++)
            {
                // Capture enumerating index here to avoid closure issues.
                int index = i;

                string expected = "<h1>Hello you are " + index + "</h1>";
                resetEvents[index] = new ManualResetEvent(false);

                var model = new Person { Age = index };
                var item = new ThreadPoolItem<Person>(model, resetEvents[index], m =>
                {
                    string result = service.Parse(template, model);

                    Assert.That(result == expected, "Result does not match expected: " + result);
                });

                ThreadPool.QueueUserWorkItem(item.ThreadPoolCallback);
            }

            // Block until all events have been set.
            WaitHandle.WaitAll(resetEvents);

            service.Dispose();
        }
开发者ID:nvegamarrero,项目名称:RazorEngine,代码行数:34,代码来源:TemplateServiceTestFixture.cs

示例2: AssertAllViewsInAssemblyCanBeCompiled

        private void AssertAllViewsInAssemblyCanBeCompiled(Assembly assembly)
        {
            var config = new TemplateServiceConfiguration();
            config.BaseTemplateType = typeof(MvcTemplateBase<>);

            var processor = new TemplateService(config);

            var resourceNames = assembly.GetManifestResourceNames();

            foreach (var resource in resourceNames)
            {
                if (resource.EndsWith(".cshtml", StringComparison.OrdinalIgnoreCase))
                {
                    var content = this.GetEmbeddedViewContent(resource, assembly);

                    // The namespace for ChildActionExtensions
                    processor.AddNamespace("System.Web.Mvc.Html");

                    processor.AddNamespace("System.Web");

                    this.AssertViewCanBeCompiled(content, resource, processor);
                }
            }

            processor.Dispose();
        }
开发者ID:RichiL,项目名称:feather-widgets,代码行数:26,代码来源:ViewsCompilationTests.cs

示例3: TemplateService_CanParseTemplatesInParallel_WithManualThreadModel

        public void TemplateService_CanParseTemplatesInParallel_WithManualThreadModel()
        {
            var service = new TemplateService();

            const int threadCount = 10;
            const string template = "<h1>Hello you are @Model.Age</h1>";

            var threads = new List<Thread>();
            for (int i = 0; i < threadCount; i++)
            {
                // Capture enumerating index here to avoid closure issues.
                int index = i;

                var thread = new Thread(() =>
                {
                    var model = new Person { Age = index };
                    string expected = "<h1>Hello you are " + index + "</h1>";
                    string result = service.Parse(template, model);

                    Assert.That(result == expected, "Result does not match expected: " + result);
                });

                threads.Add(thread);
                thread.Start();
            }

            // Block until all threads have joined.
            threads.ForEach(t => t.Join());

            service.Dispose();
        }
开发者ID:nvegamarrero,项目名称:RazorEngine,代码行数:31,代码来源:TemplateServiceTestFixture.cs


注:本文中的TemplateService.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。