草庐IT

collection_names

全部标签

c# - GC.Collect() 阻塞了吗?

我正在对我的代码运行一些基准测试,我想确保在我的一个基准测试期间不会发生垃圾收集,因为它正在清理先前测试的困惑情况。我认为我最好的机会是在开始基准测试之前强制收集。所以我在基准测试开始之前调用GC.Collect()但不确定收集是否继续在单独的线程中运行,等等并立即返回。如果它确实在BG线程上运行,我想知道如何同步调用它或至少等到它完成收集。 最佳答案 如MSDN所述-使用此方法尝试回收所有不可访问的内存。无论如何,如果它确实开始了垃圾收集,您应该在开始基准测试之前等待所有终结器完成。GC.Collect();GC.WaitForP

c# - Thread.CurrentPrincipal.Identity.Name 在 WPF 中为空

编辑简单的问题是,我怎样才能让Thread.CurrentPrincipal.Identity.Name让当前用户在WPF中登录?结束编辑我正在尝试调用一个现有方法(不在任何类型的服务中;只是POCO中的一个方法)来检索当前用户:Thread.CurrentPrincipal.Identity.Name这段代码是由其他人编写的,并且(大概)与他的ASP.NETMVC项目一起工作。我正在尝试从WPF中调用相同的方法,但名称现在为空。我能做些什么吗? 最佳答案 将Thread.CurrentPrincipal设置为newWindowsP

c# - 'System.Collections.Generic.List<float >' does not contain a definition for ' Sum'

我正在尝试使用内置的Sum()函数对float列表求和,但我不断收到此错误:ErrorCS1061:'System.Collections.Generic.List'doesnotcontainadefinitionfor'Sum'andnoextensionmethod'Sum'acceptingafirstargumentoftype'System.Collections.Generic.List'couldbefound(areyoumissingausingdirectiveoranassemblyreference?)(CS1061)我有usingSystem.Collect

python中的deque模块(collections的deque模块)

目录1.deque是python的collections中的一个类2.deque的简单使用以及它的方法2.1创建deque的方法 2.2创建deque时,并指定大小maxlen,即能装几个元素,以及deque添加元素append()方法2.3 deque的 appendleft()方法2.4 deque的clear()方法2.5 deque的copy()方法2.6deque的count方法2.7deque中的extend()方法2.8 deque中的extendleft()方法2.9deque中的index方法2.10deque中的insert方法2.11deque中的pop方法2.12deq

c# - 委托(delegate) : Method name expected error

我正在尝试让以下简单的委托(delegate)示例正常工作。根据我从中获取的一本书应该没问题,但我得到了一个Methodnameexpected错误。namespaceTestConsoleApp{classProgram{privatedelegatestringD();staticvoidMain(string[]args){intx=1;Dcode=newD(x.ToString());}}}有什么帮助吗? 最佳答案 删除():Dcode=newD(x.ToString);您想指定方法,而不是执行。

c# - "An assembly with the same simple name has already been imported"没有重复引用的错误

我收到以下错误:errorCS1704:Anassemblywiththesamesimplename'Interop.xxx.dll,Version=1.0.0.0,Culture=neutral,PublicKeyToken=nullhasalreadybeenimported.Tryremovingoneofthereferencesorsignthemtoenableside-by-side.我所看到的一切都表明我引用了两个同名的程序集,我需要删除其中一个。但是,我已经检查过并且只引用了一次。这也仅在我使用msbuild从我的开发箱上的命令行构建时发生。如果我通过VisualS

c# - EF 4.1 和 "Collection was modified; enumeration operation may not execute."异常

在过去的2天里,这让我抓狂。我有3个非常基本的类(好吧,为了便于阅读而减少了)publicclassEmployee{publicstringName{set;get;}virtualpublicEmployerEmployer{set;get;}publicEmployee(stringname){this.Name=name;}},//thisbasicallytiesEmployeeandhisroleinacompany.publicclassEmployeeRole{publicintId{set;get;}virtualpublicEmployeeEmployee{set;

c# - “不要公开通用列表”,为什么在方法参数中使用 collection<T> 而不是 list<T>

我正在使用FxCop,它显示“不要公开通用列表”的警告,建议使用Collection而不是List.首选它的原因,我知道所有这些东西,如thisSOpost中所述和MSDN以及我浏览过的更多文章。但我的问题是,我很少有方法可以进行如此繁重的计算,并且方法接受List的参数。就性能而言,这应该更快更好。但是FxCop也为此发出警告。所以一个选择是我应该将参数声明为Collection,然后使用ToList()在方法内部,然后使用它。那么优化了哪一个呢?“抑制这种情况下的警告”或“在参数中使用Collection,然后在方法本身内部使用ToList()”。 最佳

c# - Image.Save 崩溃 : {"Value cannot be null.\r\nParameter name: encoder"}

我正在尝试将图像保存到MemoryStream中,但在某些情况下会失败。代码如下:以下代码成功:Imageimg=Bitmap.FromStream(fileStream);MemoryStreamms=newMemoryStream();img.Save(ms,img.RawFormat);//Thissucceeds.以下代码失败:Imageimg=Bitmap.FromStream(fileStream);Imagethumb=img.GetThumbnailImage(thumbWidth,thumbHeight,null,System.IntPtr.Zero);MemoryS

c# - 具有路由属性的模糊 Controller 名称 : controllers with same name and different namespace for versioning

我正在尝试添加API版本控制,我的计划是为不同命名空间中的每个版本创建一个Controller。我的项目结构是这样的(注意:每个版本没有单独的区域)Controllers||---Version0||||-----ProjectController.cs||-----HomeController.cs||---Version1||-----ProjectController.cs|-----HomeController.cs我正在为路由使用RoutingAttribute。因此,Version0中的ProjectController具有路由功能namespaceMyProject.Co