草庐IT

non-existing

全部标签

c# - 从 C# : Instance does not exist in the specified category 读取性能计数器

我正在尝试从另一个.NET4应用程序中读取正在运行的.NET4应用程序的许多性能计数器。一些计数器,例如Process\%ProcessorTime和Process\PrivateBytes工作正常。但是,一旦我尝试从.NET类别之一读取性能计数器,例如.NETCLRMemory\#Gen0Collections,我就会收到以下异常:Instance'MyApplication'doesnotexistinthespecifiedCategory当我打电话时:newPerformanceCounterCategory(".NETCLRMemory").GetInstanceNames(

c# - 数字必杀技 : Where does a callvirt of a non-existent method end up?

我在其基类中标记为抽象的库类上调用属性集访问器。现在在运行时我force应用程序针对另一个版本的库运行,其中类仅实现基类的底层接口(interface),但不是从它派生的。有趣的是,.NET将运行代码,但设置该属性没有任何效果。幕后发生了什么?违规代码:MyDbParameterparam=newMyDbParameter();param.ParameterName="p";Console.Out.WriteLine("ParameterName:"+param.ParameterName);库2.0(已编译)publicsealedclassMyDbParameter:System.

c# - 区分大小写 Directory.Exists/File.Exists

有没有办法让Directory.Exists/File.Existssince区分大小写Directory.Exists(folderPath)和Directory.Exists(folderPath.ToLower())都返回true?大多数时候这无关紧要,但我使用的宏似乎在路径与大小写不匹配100%时不起作用。 最佳答案 由于Directory.Exists使用FindFirstFile不区分大小写,不。但是你可以PInvokeFindFirstFileExadditionalFlags参数设置为FIND_FIRST_EX_CA

c# - WCF,BasicHttpBinding : Stop new connections but allow existing connections to continue

.NET3.5、VS2008、使用BasicHttpBinding的WCF服务我在Windows服务中托管了一个WCF服务。当Windows服务关闭时,由于升级、定期维护等,我需要优雅地关闭我的WCF服务。WCF服务的方法最多可能需要几秒钟才能完成,典型的数量是每秒2-5次方法调用。我需要以允许任何先前调用方法完成的方式关闭WCF服务,同时拒绝任何新调用。通过这种方式,我可以在大约5-10秒内达到安静状态,然后完成Windows服务的关闭周期。调用ServiceHost.Close似乎是正确的方法,但它会立即关闭客户端连接,而无需等待任何正在进行的方法完成。我的WCF服务完成了它的方法

c# - Lazy<T> 延迟加载错误 : A field initializer cannot reference the non-static field, 方法或属性

我第一次尝试使用延迟加载来初始化我的类中的进度对象。但是,我收到以下错误:Afieldinitializercannotreferencethenon-staticfield,method,orproperty.privateLazym_progress=newLazy(()=>{longtotalBytes=m_transferManager.TotalSize();returnnewProgress(totalBytes);});在.NET2.0中,我可以执行以下操作,但我更愿意使用更新的方法:privateProgressm_progress;privateProgressPro

c# - LINQ to SQL insert-if-non-existent

我想知道是否有更简单的方法来插入表中尚不存在的记录。我仍在努力培养我的LINQtoSQL技能。这是我得到的,但似乎应该有更简单的方法。publicstaticTEntityInsertIfNotExists(DataContextdb,Tabletable,Funcwhere,TEntityrecord)whereTEntity:class{TEntityexisting=table.SingleOrDefault(where);if(existing!=null){returnexisting;}else{table.InsertOnSubmit(record);//Can'tuse

c# - 在网络中断时使用 Directory.Exists 在网络文件夹上

我公司的代码库包含以下C#行:boolpathExists=Directory.Exists(path);在运行时,字符串path恰好是公司内部网上文件夹的地址-类似于\\company\companyFolder。当从我的Windows机器到内联网的连接建立时,这工作正常。但是,当连接断开时(就像今天那样),执行上面的行会导致应用程序完全卡住。我只能通过使用任务管理器将其终止来关闭应用程序。当然,在这种情况下,我宁愿让Directory.Exists(path)返回false。有办法做到这一点吗? 最佳答案 对于这种情况,无法更改

c# - The non-generic method cannot be used with type arguments in this context 是什么意思?

我有以下类和方法:publicclassUserManager:IDisposablewhereTUser:class,global::Microsoft.AspNet.Identity.IUserwhereTKey:global::System.IEquatable{publicvirtualTaskFindByIdAsync(TKeyuserId);和:privateApplicationUserManager_userManager;publicApplicationUserManagerUserManager{get{return_userManager??Request.Ge

c# - 性能计数器 - System.InvalidOperationException : Category does not exist

我有以下类,它返回IIS每秒的当前请求数。我每分钟调用RefreshCounters以保持每秒请求数刷新(因为它是平均值,如果我将它保留太久,旧值会影响结果太多)......当我需要显示当前RequestsPerSecond时,我调用该属性。publicclassCounters{privatestaticPerformanceCounterpcReqsPerSec;privateconststringcounterKey="Requests_Sec";publicstaticobjectRequestsPerSecond{get{lock(counterKey){if(pcReqsP

c# - 在 Directory.Delete 之后,Directory.Exists 有时会返回 true 吗?

我的行为很奇怪。我有,Directory.Delete(tempFolder,true);if(Directory.Exists(tempFolder)){}有时Directory.Exists返回true。为什么?可能是资源管理器打开了吗? 最佳答案 Directory.Delete调用WindowsAPI函数RemoveDirectory.记录观察到的行为:TheRemoveDirectoryfunctionmarksadirectoryfordeletiononclose.Therefore,thedirectoryisnot