#2
yiyanxiyin2023-06-29 17:22
|
求解:
移动硬盘写数据,开始每分钟都能写20多个文件,写了300多个后,突然变慢,每分钟只能写6-7个了,为什么会变慢?附上代码:
private void Bgw_DoWork(object sender, DoWorkEventArgs e)
{
int selIndex = Get_Tabcontrol_SelectIndex();
if(selIndex == 0 && listBox_segd.Items.Count > 0)
{
WriteSegy writesegy = new WriteSegy();
for (int i = 0; i < listBox_segd.Items.Count; i++)
{
if (Bgw.CancellationPending)
{
e.Cancel = true;
break;
}
else
{
ReadSegd readSegd = new ReadSegd(listBox_segd.Items[i].ToString());
SegdHeader2SegyHeader segdhd2segyhd = new SegdHeader2SegyHeader(readSegd.Gh, readSegd.Th);
string dir = Get_combox_Text();
writesegy.WriteSegy_Segd(listBox_segd.Items[i].ToString(), dir, segdhd2segyhd.Textheader, segdhd2segyhd.Binaryheader,
segdhd2segyhd.Traceheader, segdhd2segyhd.Samples, segdhd2segyhd.Trace_num, segdhd2segyhd.Seek, segdhd2segyhd.Trcheader_bytes);
Bgw.ReportProgress((i + 1) * 100 / listBox_segd.Items.Count);
}
}
}
}
public void WriteSegy_Segd(string segdfile, string dir, char[] txh, dynamic[] bh, List<List<dynamic>> trch, int samples, long num, int seek, int trcheader_bytes)
{
string sgyfile = dir + @"\" + Path.GetFileNameWithoutExtension(segdfile) + ".sgy";
if (File.Exists(sgyfile))
{
MessageBox.Show("文件已存在 !", " Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); return;
}
using (FileStream fs = new FileStream(segdfile, FileMode.Open, FileAccess.Read))
{
using (FileStream fs1 = new FileStream(sgyfile, FileMode.Create, FileAccess.ReadWrite))
{
using (BinaryReader br = new BinaryReader(fs))
{
using (BinaryWriter wr = new BinaryWriter(fs1))
{
wr.Write(txh);
for (int i = 0; i < bh.Count(); i++)
{ byte[] bb = BitConverter.GetBytes(bh[i]); Array.Reverse(bb); wr.Write(bb); }
fs.Seek(seek, SeekOrigin.Begin);
for (int i = 0; i < num; i++)
{
for (int k = 0; k < trch[i].Count(); k++)
{
byte[] bb = BitConverter.GetBytes(trch[i][k]);
Array.Reverse(bb);
wr.Write(bb);
}
br.ReadBytes(trcheader_bytes);
wr.Write(br.ReadBytes(samples * 4));
}
}
}
}
}
}