我有一个使用性能计数器的应用程序,已经工作了几个月.现在,在我的开发机器和另一台开发人员机器上,当我调用PerformanceCounterCategory.Exists时它已经开始挂起.据我所知,它无限期地挂起.我使用哪个类别作为输入并不重要,使用API的其他应用程序表现出相同的行为.
调试(使用MS Symbol Servers)显示它是对挂起的Microsoft.Win32.RegistryKey的调用.进一步的调查表明,这条线是挂起的:
while (Win32Native.ERROR_MORE_DATA == (r = Win32Native.RegQueryValueEx(hkey, name, null, ref type, blob, ref sizeInput))) {
Run Code Online (Sandbox Code Playgroud)
这基本上是一个尝试为性能计数器数据分配足够内存的循环.它开始于size = 65000并进行一些迭代.在第4次通话中size = 520000,Win32Native.RegQueryValueEx挂起时.
此外,相当令人担忧的是,我在PerformanceCounterLib.GetData的参考源中找到了这条评论:
// Win32 RegQueryValueEx for perf data could deadlock (for a Mutex) up to 2mins in some
// scenarios before they detect it and exit gracefully. In the mean time, ERROR_BUSY,
// ERROR_NOT_READY etc can be seen by other concurrent calls (which is the reason for the
// wait loop and …Run Code Online (Sandbox Code Playgroud) 关于我之前的问题,我需要检查一下将由Castle Windsor实例化的组件,在我的代码使用完之后是否可以进行垃圾回收.我在前一个问题的答案中尝试了这个建议,但它似乎没有按预期工作,至少对我的代码而言.所以我想编写一个单元测试来测试在我的一些代码运行之后是否可以对特定对象实例进行垃圾回收.
这有可能以可靠的方式进行吗?
编辑
我目前根据Paul Stovell的答案进行了以下测试,该答案成功:
[TestMethod]
public void ReleaseTest()
{
WindsorContainer container = new WindsorContainer();
container.Kernel.ReleasePolicy = new NoTrackingReleasePolicy();
container.AddComponentWithLifestyle<ReleaseTester>(LifestyleType.Transient);
Assert.AreEqual(0, ReleaseTester.refCount);
var weakRef = new WeakReference(container.Resolve<ReleaseTester>());
Assert.AreEqual(1, ReleaseTester.refCount);
GC.Collect();
GC.WaitForPendingFinalizers();
Assert.AreEqual(0, ReleaseTester.refCount, "Component not released");
}
private class ReleaseTester
{
public static int refCount = 0;
public ReleaseTester()
{
refCount++;
}
~ReleaseTester()
{
refCount--;
}
}
Run Code Online (Sandbox Code Playgroud)
我是否正确地假设,基于上述测试,我可以得出结论,使用NoTrackingReleasePolicy时Windsor不会泄漏内存?
我在我的WP7应用程序中添加了一个新的XAML页面,我需要应用程序在这个新页面上启动.我怎么做 ?
我找不到在App.xaml或App.xaml.cs中任何地方引用的MainPage(这是当前/默认的起始页).
如果我有以下代码:
MyType<int> anInstance = new MyType<int>();
Type type = anInstance.GetType();
Run Code Online (Sandbox Code Playgroud)
通过查看类型变量,如何找出实例化的"anInstance"类型参数?可能吗 ?
我有一个存储过程,其参数没有默认值,但可以为null.但我无法弄清楚如何使用Dapper传递null.我可以在ADO中做得很好.
connection.Execute("spLMS_UpdateLMSLCarrier", new { **RouteId = DBNull.Value**, CarrierId = carrierID, UserId = userID, TotalRouteRateCarrierId = totalRouteRateCarrierId },
commandType: CommandType.StoredProcedure);
Run Code Online (Sandbox Code Playgroud)
例外:
System.NotSupportedException was caught
Message=The member RouteId of type System.DBNull cannot be used as a parameter value
Source=Dapper
StackTrace:
at Dapper.SqlMapper.LookupDbType(Type type, String name) in C:\Dev\dapper-git\Dapper\SqlMapper.cs:line 348
at Dapper.SqlMapper.CreateParamInfoGenerator(Identity identity) in C:\Dev\dapper-git\Dapper\SqlMapper.cs:line 1251
at Dapper.SqlMapper.GetCacheInfo(Identity identity) in C:\Dev\dapper-git\Dapper\SqlMapper.cs:line 908
at Dapper.SqlMapper.Execute(IDbConnection cnn, String sql, Object param, IDbTransaction transaction, Nullable`1 commandTimeout, Nullable`1 commandType) in C:\Dev\dapper-git\Dapper\SqlMapper.cs:line 532
at Rating.Domain.Services.OrderRatingQueueService.UpdateLMSLCarrier(Int32 totalRouteRateCarrierId, Int32 carrierID, Int32 …Run Code Online (Sandbox Code Playgroud) 所以我在VS 14 CTP中有一个ASP .NET vNext项目.我的目标是.NET Framework 4.5.1.我添加了对NuGet包的引用,该包没有针对vNext的构建.
Visual Studio现在显示编辑器/ Intellisense中没有错误的包的用法.但是在编译时,我得到"未找到名称空间'MyPackage'"错误.
我的理解是,只要我定位现有的.NET Framework 4.5.1,我就可以添加对.NET Framework程序集的引用.这不是这种情况吗?我可以解决此错误吗?
因此,我的一个网站有一个应该在应用程序启动之前运行的PreApplicationStartMethod:
[assembly: PreApplicationStartMethod(typeof(ServiceStackAppHost), "Start")]
Run Code Online (Sandbox Code Playgroud)
此方法执行一些引导并依赖于某些配置.
现在,我想编译网站作为我的自动构建过程的一部分 - 所以我调用aspnet_compiler.exe,因为它运行PreApplicationStartMethod而失败:
AfterBuild:
C:\ Windows\Microsoft.NET\Framework64\v4.0.30319\aspnet_compiler.exe -v temp -p C:\ Projects\error ASPRUNTIME:预应用程序启动初始化方法启动类型RedactedNameSpace.ServiceStackAppHost引发异常以下错误消息:依赖项的解析失败,type ="..."
在编译网站时,如何避免aspnet_compiler.exe调用PreApplicationStartMethod?
在一个繁忙的ASP .NET网站上,我有一个Dictionary,它充当缓存,基本上存储键/值对以供以后检索.
在高负载时,Dictionary有时会进入一个状态,每当我调用ContainsKey或Add方法时它总是抛出一个IndexOutOfRangeException.异常发生在私有FindEntry方法中.
我怀疑这可能是由于同步问题,但我不确定.
谁能告诉我在哪种情况下会发生这种情况?我的目标是收集足够的信息,以便我可以在开发环境中重现问题.
我正在尝试使用Less Css,我正在使用Visual Studio 2010.
如果编辑器提供对语法高亮和Intellisense for Less的支持,例如着色和建议变量,那将是很好的.我有什么选择让它发挥作用?我是否需要为它编写插件,或者如何将其添加到VS?这已经存在吗?
.net ×7
c# ×5
asp.net ×2
asp.net-core ×1
clr ×1
dapper ×1
debugging ×1
dictionary ×1
intellisense ×1
less ×1
reflection ×1
silverlight ×1
unit-testing ×1