English 中文(简体)
“项目已经添加 。 字典中的密钥” 的工作周期每次使用相同的密钥, 但有不同的值
原标题:Workaround to "Item has already been added. Key in dictionary" using the same key everytime but with a different value

在“用户环境变量”下,我添加了一个变量,名为“eg”的密钥。

TMP_VAR

和数值eg。

C:	empsim

在 VS2010. Net 4. 0 创建的 C# 应用程序中启动新进程, 并设置 StartInfo. EnvironmentVables. Add (“ TMP_VAR” ) 时, C: envesim ; 在双击 exe 文件时我得到这个错误 :

Item has already been added. Key in dictionary:  TMP_VAR  Key being added:  TMP_VAR 

然而,如果我从 VS2010 (按 F5) 开始, 就不会出错 。

我的理论是,VS2010 不知何故以某种“壳状”开始这一过程, 并覆盖了“壳状”中的变量。

此外,我的应用程序启动多个进程, 其键值相同, 但值不同。 密钥不能被更改。 它必须是 TMP_ VAR, 但允许更改值 。

我的问题是:我的应用程序如何启动一个新的进程, 使用 StartInfo. Environmental Vables 来设置相同的键。 或者我的问题还有另一个明智的解决方案吗?

最佳回答

流程可以检查关键TMP_VAR的存在,而不必添加,只要存在,就可以相应更改数值。

if(StartInfo.EnvironmentVariables.ContainsKey("TMP_VAR"))
    StartInfo.EnvironmentVariables["TMP_VAR"] = "C:/temp/sim";
else
    StartInfo.EnvironmentVariables.Add("TMP_VAR", "C:/temp/sim");
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签