使用Block在网站上的行为不同VS windows窗体 [英] USING block behaves differently in website vs windows form

查看:99
本文介绍了使用Block在网站上的行为不同VS windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通过在一些网站的数据库code调试器步进,并且应用了数据库的更改之前结束执行。但他们仍然写入数据库!

I was stepping through the debugger in some website database code, and ended execution before the database changes were applied. But they were still written to the database!

我试图重新使用Windows窗体应用程序的问题,并没有写入数据库(预期的行为)。我又回到了网站,它的没有

I tried to recreate the problem using a Windows Form application, and it didn't write to the database (expected behaviour). I went back to the website, and it did.

下面是一个简单的例子页面。我在网上的网站运行此的,如果它的确与众不同:

Here is a simple example page. I am running this in a web site if it makes a difference:

<%@ Page Language="C#" %>
<%@ Import Namespace="System.Diagnostics" %>

<!DOCTYPE html>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {
        using (MsSqlDataContextDataContext db = new MsSqlDataContextDataContext())
        {
            Product product = db.Products.First(p => p.id == 21);
            Debug.WriteLine("Line 1");
            // I learnt the hard way that if you try to update the database with the value
            // that already exists, it seems to get optimised away.
            // The update must a new value. 
            product.Type = "bogus" + DateTime.UtcNow.Ticks;
            Debug.WriteLine("Line 2");  // <- Breakpoint here
            db.SubmitChanges();
        }
    }
</script>

<html>
<head runat="server">
</head>
</html>

我最终执行(<大骨节病>移 + <大骨节病> F5 )在断点处,的的第二次调试印刷或的SubmitChanges( )得到执行。 2号线是的的输出到调试窗口,但对数据库的修改的制作。

I end execution (Shift+F5) at the breakpoint, before the second debug print or SubmitChanges() get executed. "Line 2" is not output to the debug window, but the database changes are made.

在Windows窗体中运行相同的测试并具有相同的行为。

Running the same test in a Windows Form does behave the same.

时的页面生命周期,或会话管理在某种程度上干扰吗?这怎么可能连,2号线不打印!

Is the page life-cycle, or session management somehow interfering here? How is this even possible, Line 2 doesn't get printed!

推荐答案

当您在winform应用程序停止调试,这个过程被终止和你的code停止执行。

When you stop debugging in the winform app, the process is terminating and your code stops executing.

在asp.net不是这种情况。当你停止调试器(通常情况下)它不会终止IIS进程,只是分离调试程序。您code继续运行,请求完成。

In asp.net this is not the case. When you stop the debugger (usually) it won't terminate the iis process, just detach the debugger. Your code continues running and the request completes.

有对这个问题的重复,没有代表,以纪念这是重复的。

There are duplicates for this question, have no rep to mark this as duplicate.

这篇关于使用Block在网站上的行为不同VS windows窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆