我想弄清楚gdi +图形容器究竟是如何与不同的图形单元一起工作的.看看下面的代码.它编译,您可以将其粘贴到一个全新的形式.
void Form2_Paint(object sender, PaintEventArgs e)
{
var gfx = e.Graphics;
System.Diagnostics.Debug.WriteLine("DpiX={0}, DpiY={1}", gfx.DpiX, gfx.DpiY);
gfx.PageUnit = GraphicsUnit.Inch;
var pen = new Pen(Color.Black, 0.01f);
// Create outer container, 2 inches in size with X and Y set to 0.1 inches
var outerContainer = gfx.BeginContainer(
new RectangleF(0.1f, 0.1f, 2, 2),
new RectangleF(0, 0, 2, 2),
GraphicsUnit.Pixel);
// Draw the outer rectangle
gfx.DrawRectangle(pen, new Rectangle(0, 0, 2, 2));
// Create inner container, 1 inch in size with X and Y set …Run Code Online (Sandbox Code Playgroud) 我对 ASP.NET Core 完全陌生,所以我可能在 50 英里之外遗漏了一些东西,因为我在这上面花了 3 个小时无济于事。
我在 VS 2017 中制作了一个 Web 应用程序,由 Kestrel 托管,它在 IIS Express 下运行(当你创建一个新的 Web 应用程序时,这是所有默认设置)。当我按 F5 时,应用程序启动,我的 Chrome 浏览器打开,我看到“hello world”式的输出。当我关闭此浏览器窗口时,应用程序终止。
现在,我需要在后台执行一些任务,并且需要这些任务具有清理逻辑 - 我发现这IHostedService允许我执行此操作。
该文件指出:
当您注册 IHostedService 时,.NET Core 将分别在应用程序启动和停止期间调用 IHostedService 类型的 StartAsync() 和 StopAsync() 方法。
我已经做好了:
public void ConfigureServices(IServiceCollection services)
{
services.AddHostedService<MyBackgroundService>();
}
Run Code Online (Sandbox Code Playgroud)
服务按预期启动,一切正常。极其简单的东西。但它永远不会停止,至少不会优雅地停止。
当我关闭那个自动启动的浏览器窗口时,我的应用程序也随之关闭,但是我的IHostedService服务中的这个方法:
public Task StopAsync(CancellationToken cancellationToken)
{
...
}
Run Code Online (Sandbox Code Playgroud)
永远不会被调用。
我已经尝试了文档中提供的示例,它显示了相同的问题 - 在 VS 中尝试时从未完成清理。
我注意到来自名为“ASP.NET Core Web Server”的输出通道的特殊信息:
public void …Run Code Online (Sandbox Code Playgroud) c# visual-studio-2017 asp.net-core-2.1 asp.net-core-hosted-services