- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在 Visual Studio 即时窗口中运行一些相当简单的代码。所有代码所做的就是从文件中读取一些 JSON 输入,并使用它来调用一些其他方法,以将值加载到数据库中。这是代码块:
using Newtonsoft.Json.Linq;
using System;
using System.IO;
namespace POST.API
{
public class Initialization
{
public const string JSON_DATA_FILE = "C:\\OHA_SDD_POST_Development\\POST\\POST.API\\Services\\Setup\\InitializationData.json";
public const string JSON_OBJKEY_DOMAIN = "Domain";
public const string JSON_OBJKEY_ACCOUNTDOMAINTYPE = "AccountDomainType";
public const string JSON_OBJKEY_ORGLOCTYPE = "OrganizationLocationType";
public JObject POSTDataInitJObject;
public JArray Domains;
public JArray AccountDomainRoles;
public JArray OrganizationLocationTypes;
public API.Services.Domain SvcDomain;
public API.Services.Organization SvcOrganization;
public API.Services.Location SvcLocation;
/// <summary>
///
/// </summary>
/// <param name="JsonDataFile"></param>
public Initialization(string JsonDataFile = JSON_DATA_FILE)
{
string JsonData = File.ReadAllText(JsonDataFile);
POSTDataInitJObject = JObject.Parse(JsonData);
Domains = (JArray)POSTDataInitJObject[JSON_OBJKEY_DOMAIN];
AccountDomainRoles = (JArray)POSTDataInitJObject[JSON_OBJKEY_ACCOUNTDOMAINTYPE];
OrganizationLocationTypes = (JArray)POSTDataInitJObject[JSON_OBJKEY_ORGLOCTYPE];
}
/// <summary>
///
/// </summary>
public void Load()
{
LoadDomains();
LoadOrganizationLocationTypes();
}
/// <summary>
///
/// </summary>
/// <param name="Replace"></param>
public void LoadDomains(bool Replace = true)
{
SvcDomain = new API.Services.Domain();
if (Replace)
{
SvcDomain.ClearAllDomains(true);
}
foreach (var i in Domains)
{
SvcDomain.AddDomain(new API.Models.Domain
{
Code = (string)i["Code"],
Definition = new API.Models.TypeDefinition
{
Name = (string)i["Name"],
Description = (string)i["Description"],
Order = Int32.Parse((string)i["Order"])
}
});
}
}
/// <summary>
///
/// </summary>
/// <param name="Replace"></param>
public void LoadOrganizationLocationTypes(bool Replace = true)
{
SvcLocation = new API.Services.Location();
if (Replace)
{
SvcLocation.ClearAllOrganizationLocationTypes();
}
foreach (var i in OrganizationLocationTypes)
{
SvcLocation.AddOrganizationLocationType(new API.Models.OrganizationLocationType
{
Definition = new API.Models.TypeDefinition
{
Name = (string)i["Name"],
Description = (string)i["Description"],
Order = Int32.Parse((string)i["Order"])
}
});
}
}
}
}
我可以在即时窗口中成功实例化该对象,但是当我随后尝试在该实例上调用该 Load() 方法时,我得到:
在 mscorlib.dll 中发生类型为“System.Threading.ThreadAbortException”的第一次机会异常
评估需要线程暂时运行。使用 Watch 窗口执行评估。
我已经关闭了 Options -> Debug -> Enable property evaluation 和其他隐式函数调用。
让我难住了......看起来 super 简单,我完全无法通过它。
最佳答案
你正在直接或间接地调用一些包含 this 的代码:
System.Diagnostics.Debugger.NotifyOfCrossThreadDependency()
为什么代码会有那个?
Some of you might have ran into this situation where you try to evaluate a property or a method during debug time, and get this message in the value cell of the watch:
这个问题有一个快速的“解决方法”。如果仔细看,您会在消息后看到一个小圆形图标:
When we break the debugger and try to evaluate a property which requires running code, we can only run code in the current thread. All other threads are frozen to minimize the system state impact… But, what if my property requires another thread to run in order to complete evaluation? For example, if I am doing a remote call, I will most likely need the ThreadPool threads for that… But all other threads are frozen… which will result in a “deadlock”. The debugger has a protection measure against that, which gives a max of 5 seconds to the evaluation code to run. If the code did not finish to run within the time limit, For example, when we are blocked due to a frozen thread, the watch will be “hanged” for 5 seconds, and after that evaluation will be aborted. We will get this message to notify us of the problem:
所以那行代码会导致您收到消息:
The debugger will not allow it automatically, to avoid state changes, and instead, will give the user the “The function evaluation requires all threads to run” message.
如果你打开了调试器,那么:
If the user decides it’s OK to let all threads run, he can push the icon next to the message, which will cause the debugger to run the property code a second time, this time with all threads running, and not aborting on the NotifyOfCrossThreadDependency method.
请阅读this文章了解更多详情。
此外,我不确定您在即时窗口中运行所有代码的理由是什么。或许您可以编写一个小型控制台应用程序并改为运行该应用程序。
关于c# - 在立即窗口中调用C#方法VS,得到 'System.Threading.ThreadAbortException',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42214982/
我有一个带有帮助页面的 Web API 2 项目,该项目在本地运行良好,但当我将其推送到 Azure 时抛出此错误: Method not found: 'System.String System.S
我有两台服务器,但通常运行相同的设置 - IIS、SQL Server 等。一台给我这个错误,另一台没有。我从 Visual Studio 向两者发布相同的代码。 它们都在运行 .NET CLR Ve
System.out声明为 public static final PrintStream out。 但是你可以调用System.setOut()重新分配它。 嗯?如果它是 final,这怎么可能?
System.out被声明为 public static final PrintStream out。 但是您可以调用System.setOut()重新分配它。 嗯?如果是 final,这怎么可能?
我有这个 linq 查询: private void GetReceivedInvoiceTasks(User user, List tasks) { var areaIds = user.A
我有一个 MonoTouch 应用程序,当我为设备编译它时,出现以下错误: Error MT2002: Can not resolve reference: System.Boolean System
您好,我有一个名为 DailyVisitReport 的 View 。在该 View 中,我有两个名为 FromDate 和 toDate 的字段。如果我选择 FromDate 和 ToDate 取决
是否可以从 ObjectContext 对象中读取元组列表? 我在存储过程中有类似这样的数据库查询 SELECT T.Id as Item1, -- this is guid T.Wo
我正在尝试创建 Odata 端点,但每当我尝试执行任何涉及日期的查询时都会收到此错误。 我在下面的非常简单示例中重新创建了它。 数据库表 EDMX(片段)
我正在尝试创建 Odata 端点,但每当我尝试执行任何涉及日期的查询时都会收到此错误。 我在下面的非常简单示例中重新创建了它。 数据库表 EDMX(片段)
我有一个方法可以从数据读取器的数据中生成类类型列表。 if (datareader != null && datareader .HasRows) { Dictionary pDict= GetP
我有一些旧的 C++ 代码,它们使用 stdio 进行输入和输出。该代码还通过 fork 生成新进程。它将 stdio 重新映射到每个新进程,以便每个 session 获取其各自的数据。 我正在考虑使
我的应用程序可以很好地构建/链接/部署到模拟器,但我只是第一次尝试将应用程序构建/部署到真实设备,并且链接器失败。 我不使用 System.Console或 ConsoleColor在我的应用程序的任
主要是我很好奇。 我们有一个名为 Unit 的对象在我们的代码库中 - 代表桥梁或道路的组件。在我们的例子中,看到带有 Unit 的 ReactiveUI 命令可能会模棱两可。作为声明中的泛型之一。
我试图将Object变量转换为StreamWriter。但是,它不起作用。有什么错? StreamWriter file = (StreamWriter) myObject; 最佳答案 myObjec
为什么以下不编译? using System; using System.Linq; using System.Linq.Expressions; public static class Extens
我正在使用 Visual Studio Community 2015 开发面向 .NET 4.5 的 Visual Basic 应用程序.我没有编写应用程序,所以我使用 NuGet 添加了所有缺失的依
我刚刚开始使用 powershell,我正在制作一个非常简单的加密功能。我想获取字符串中的每个字符,将其转换为 int 并添加一个选定的数字,然后将其转换回一个字符。 这工作正常: function
一些使用我的应用程序的人似乎变得越来越 System.MissingMethodException: Method not found: 'System.Object System.Windows.T
我是 C# 和实体的新手 我想知道是否有人在这里帮助我。我选择了哪个返回我的 customerid,所以我想将它作为参数传递给我的构造函数,我的构造函数参数类型是 guid 但我的选择类型不同,我不知
我是一名优秀的程序员,十分优秀!