本文整理汇总了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();
}
示例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();
}
示例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();
}