并行 foreach 字符数组空白
我正在尝试创建一个并行的 foreach 循环来处理 fasta 文件。 我已将 fasta 文件加载到 ConcurrentDictionary 中并具有并行 foreach 设置,但是当我去处理 ConcurrentDictionary 我的 char 数组时 即使 ConcurrentDictionary 值仍为空,也会引发错误 永远不会是空白。我尝试调试,但对于多个线程来说非常困难 告诉发生了什么事。 谢谢 凯西
Parallel.ForEach(fastainfomation, info =>
{
line = info.Key;
name = info.Key;
secondline = info.Value;
if (name != "")
{
name = name.TrimEnd('\r', '\n');
char[] secondlineprimer = secondline.ToCharArray();
string primer = "";
string primername = "";
string primergroup = "";
for (int ii = 0; ii < 8; ii++)
{
primer += secondlineprimer[ii];
} ...
I'm trying to create a parallel foreach loop to processes a fasta file.
I've loaded the fasta file into a ConcurrentDictionary and have the parallel
foreach setup but when I go to process the ConcurrentDictionary my char array
throws an error about being blank even though the ConcurrentDictionary value
is never blank. I tried to debug but with the multiple threads it was very difficult
to tell what was going on.
Thank you
Casey
Parallel.ForEach(fastainfomation, info =>
{
line = info.Key;
name = info.Key;
secondline = info.Value;
if (name != "")
{
name = name.TrimEnd('\r', '\n');
char[] secondlineprimer = secondline.ToCharArray();
string primer = "";
string primername = "";
string primergroup = "";
for (int ii = 0; ii < 8; ii++)
{
primer += secondlineprimer[ii];
} ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,您没有在 lambda 表达式中声明
line
、name
等,这表明它们是在其他地方声明的 - 这意味着它们将被所有调用共享。这本身就足以使您的代码变得不安全。您还应该使用
Substring
而不是像这样重复的字符串连接...除此之外,您的问题并没有真正包含足够的信息来帮助您进一步 - 请阅读 写出完美的问题并且更加注重清晰度。
The fact that you're not declaring
line
,name
etc within the lambda expression suggests that they're declared elsewhere - which means that they'll be shared by all the invocations. That in itself is enough to make your code unsafe.You should also use
Substring
rather than repeated string concatenation like this...Beyond that, your question doesn't really contain enough information to help you further - please read writing the perfect question and pay more attention to clarity.