我有这个正则表达式,我在Parallel.ForEach<string>
. 安全吗?
Regex reg = new Regex(SomeRegexStringWith2Groups);
Parallel.ForEach<string>(MyStrings.ToArray(), (str) =>
{
foreach (Match match in reg.Matches(str)) //is this safe?
lock (dict) if (!dict.ContainsKey(match.Groups[1].Value))
dict.Add(match.Groups[1].Value, match.Groups[2].Value);
});