| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1411 人关注过本帖
标题:写数据速度问题求助
只看楼主 加入收藏
hotpig1981
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2022-11-26
收藏
 问题点数:0 回复次数:1 
写数据速度问题求助
求解:
移动硬盘写数据,开始每分钟都能写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));                                 
                            }
                        }
                    }
                }
            }
        }


搜索更多相关主题的帖子: 数据 int new string Count 
2022-11-26 17:33
yiyanxiyin
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:9
帖 子:242
专家分:1856
注 册:2023-6-29
收藏
得分:0 
监测一下内存cpu的占用情况, 然后再排查
2023-06-29 17:22
快速回复:写数据速度问题求助
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.037827 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved