相关疑难解决方法(0)

为什么尝试/最终而不是"使用"语句有助于避免竞争条件?

此问题涉及另一个帖子中的评论:取消实体框架查询

为清楚起见,我将从那里重现代码示例:

    var thread = new Thread((param) =>
    {
        var currentString = param as string;

        if (currentString == null)
        {
            // TODO OMG exception
            throw new Exception();
        }

        AdventureWorks2008R2Entities entities = null;
        try // Don't use using because it can cause race condition
        {
            entities = new AdventureWorks2008R2Entities();

            ObjectQuery<Person> query = entities.People
                .Include("Password")
                .Include("PersonPhone")
                .Include("EmailAddress")
                .Include("BusinessEntity")
                .Include("BusinessEntityContact");
            // Improves performance of readonly query where
            // objects do not have to be tracked by context
            // Edit: But it doesn't …
Run Code Online (Sandbox Code Playgroud)

.net c# asynchronous entity-framework race-condition

24
推荐指数
2
解决办法
1999
查看次数

visual studio 2010调试器 - 尽管条件错误,仍会进入"if"语句

我正在使用VS 2010 Professional(在Windows 7 Professional 64上),使用WCF 4.0编写.我有以下代码:

        if (responseMessage.StatusCode == HttpStatusCode.NotFound)
        {                
            throw new ContentNotFoundException(contentId, SSPErrorCode.PartnerRestGetStream404);
        }
Run Code Online (Sandbox Code Playgroud)

当安装调试器的过程中,在"if"语句或在此之前,已经设置断点,而条件为假(responseMessage.StatusCode是"OK"),调试器的步骤到"if"语句.然后它跳过"throw"语句而不做任何事情,然后继续执行代码.

我试过了:

重新启动VS,注销我的Windows用户,重新启动,清洗液,再构建它,重建它,回收应用程序池,resarting IIS,加入的条件里面的"if"语句和内部更多的代码 - 没有到目前为止的工作.

在某个地方必须有一个缓存,我可以清理它以摆脱它,但是什么,在哪里?

谷歌搜索此我只找到HTTP: - social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/d4b70fd7-b74a-42ce-a538-7185df3d3254/,所以我手动尝试设置断点,它没"在这个班级中打破了,虽然在其他班级也是如此.

我想在不重新安装VS的情况下解决这个问题.先感谢您!


更新:

  1. 由于我提出这个并且找不到答案,我继续我的项目.
  2. 我偶然发现了这个问题,John MacIntyre在这篇文章中报告了这个问题,结果是一个简化的例子:
using System; 

namespace IEnumerableBug2 
{ 
    class Program 
    {
        static void Main(string[] args) 
        {
            if (new object() == null)
                throw new Exception();
            try { }  catch { }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

更新#2:

请注意,我的方法中还有一个try-catch语句,在'if'语句后面几行.

我刚试过再次复制这个bug,但失败了.对于可能需要它的其他人,我将把问题留在stackoverflow上,但是,正如我所写,我不再能够重现这种行为.

debugging visual-studio-2010

8
推荐指数
1
解决办法
2950
查看次数