目前这么些暂时没发现数据丢失问题,需要继续验证。
string fullPath = @"C:\Users\cyan\Desktop\bbb.csv";
FileStream fs = new FileStream(fullPath, System.IO.FileMode.Create, System.IO.FileAccess.Write);
StreamWriter ObjWrites = default(StreamWriter);
ObjWrites = new StreamWriter(fs,Encoding.Default);
//在如下双循环里面写入csv,涉及到多个线程共同写入,所以需要安全同步写入,否则会出现数据遗漏现象。
dynamic swline = StreamWriter.Synchronized(ObjWrites);
Parallel.ForEach(list2,i=>
{
string a1 = i.Name;
double a2 = Convert.ToDouble(i.longa);
double a3 = Convert.ToDouble(i.lata);
foreach (var j in list)
{
string b1 = j.Name;
double b2 = Convert.ToDouble(j.longa);
double b3 = Convert.ToDouble(j.lata);
if (a1 != b1)
{
double c1 = Distance(a2, a3, b2, b3);
if (c1 == 0)
{
string txt = string.Concat("并发: ", ",", a1, ",", b1, ",", a2, ",", a3, ",", b2, ",", b3, ",", c1);
swline.WriteLine(txt);
}
}
}
});
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:https://bianchenghao.cn/35703.html