如果字典不包含给定键的值,它是否只返回false,或者由于线程竞争条件它也会返回false,就像另一个线程添加/更新某些东西一样?
代码问题:
ConcurrentDictionary<int, string> cd = new ConcurrentDictionary<int, string>();
// This might fail if another thread is adding with key value of 1.
cd.TryAdd(1, "one");
// Will this ever fail if no other thread ever removes with the key value of 1?
cd.TryRemove(1);
Run Code Online (Sandbox Code Playgroud)
编辑: 我认为它只会返回false,如果它不包含给定键的值,但想要绝对确定.
我有一个设置,可以使用标准REST获取一些资源,这很容易记录在swagger中.当更改后,使用websockets将相同的资源推送到客户端,因此客户端不必在间隔的基础上进行拉取.
但是我怎么能在招摇中记录下来呢?它甚至可能吗?如果没有,您建议使用什么其他工具来记录REST API和websocket部分?
我希望能够从正在运行的Web角色中获取名称(在创建托管服务时命名)和部署的位置(North Europe,Asia Anywere等).我不想依赖证书和订阅ID.
就像是:
// Current role name. Ex: WebRole_IN_0
RoleEnvironment.CurrentRoleInstance.Id
// Deployment id of the role. Ex: 44b522f7e8b94412b046bbab08116d87
RoleEnvironment.DeploymentId
Run Code Online (Sandbox Code Playgroud)
但只是返回部署名称和部署位置.
如果不使用订阅ID和证书文件通过REST API,这是否可行?
当我打开现有的C#项目或创建一个新的C#项目时,我的visual studio 2015 RC崩溃了.如果我创建或打开C++项目,它不会崩溃.
这是堆栈:
Application: devenv.exe
Framework Version: v4.0.30319
Description: The application requested process termination through System.Environment.FailFast(string message).
Message: Microsoft.VisualStudio.Composition.CompositionFailedException: Expected 1 export(s) with contract name "Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.MiscellaneousFilesWorkspace" but found 0 after applying applicable constraints.
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports(ImportDefinition importDefinition)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports[T,TMetadataView](String contractName, ImportCardinality cardinality)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T,TMetadataView](String contractName)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T](String contractName)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExport[T]()
at Microsoft.VisualStudio.Composition.ExportProvider.GetExportedValue[T]()
at Microsoft.VisualStudio.ComponentModelHost.ComponentModel.GetService[T]()
at Microsoft.VisualStudio.LanguageServices.Implementation.LanguageService.AbstractPackage`2.Initialize()
at Microsoft.VisualStudio.LanguageServices.CSharp.LanguageService.CSharpPackage.Initialize()
Stack:
at System.Environment.FailFast(System.String, System.Exception)
at Microsoft.CodeAnalysis.FailFast.OnFatalException(System.Exception)
at Microsoft.CodeAnalysis.ErrorReporting.FatalError.Report(System.Exception, System.Action`1<System.Exception>)
at Microsoft.VisualStudio.LanguageServices.CSharp.LanguageService.CSharpPackage.Initialize()
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports(Microsoft.VisualStudio.Composition.ImportDefinition)
at Microsoft.VisualStudio.Composition.ExportProvider.GetExports[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, …Run Code Online (Sandbox Code Playgroud) 我是一个长期的C#开发人员并且试图抓住F#并且这样做我想做一个我需要以下内容的小项目:是否可以使用以下行为来创建函数以及如何?注意:我知道它可能有ref,但我希望它更"纯粹"的功能.
let count (x:int) (y:iny): (int -> int * int) =
??
let myCount = count 1
// --------
let myCount, value = myCount 2;; // value is now 3
let myCount, value = myCount 3;; // value is now 6
let myCount, value = myCount 1;; // value is now 7
Run Code Online (Sandbox Code Playgroud)