2 lj2002aaa188 lj2002aaa188 于 2016.09.25 14:10 提问

ContextSwitchDeadlock CLR 无法从 COM 上下文...

程序要读取处理1.2万个text文件,从中提取数据。调试出现错误,貌似执行时间过长系统出现异常所致。网上查询结果均是在 调试设置里把 ,对应的调试选项去掉,仅不再提示错误窗口,但运行时还是死机。请问各位大侠,这种执行时间长,文件访问量达的情况下,代码应该在吗处理?

private void button4_Click_1(object sender, EventArgs e)
{
string[,] SurfaceInfo;
string[] tmpdata, table, TData;
string FileName, tmpStr;
int nums,IDnums;
DateTime starDay, endDay, tmpDay;
//读取地面资料
SurfaceInfo = Red_SetInfo();
IDnums = SurfaceInfo.GetLength(0) - 1;
//先写表头
FileName = "最低气温数据.txt";
StreamWriter sw = new StreamWriter(System.Environment.CurrentDirectory + "\" + FileName, true, System.Text.Encoding.Default);
tmpStr = IDnums.ToString() + "\r\n";
sw.Write(tmpStr);
tmpStr = "年 月 日";
for (int i = 0; i < IDnums; i++)
{
tmpStr = tmpStr + "\t" + SurfaceInfo[i+1, 1];
}
tmpStr = tmpStr + "\r\n";
sw.Write(tmpStr);
sw.Close();

        starDay=DateTime.Parse("1980-01-01 00:00:00");
        endDay=DateTime.Parse("2014-12-31 00:00:00");
        tmpDay = starDay;
        TimeSpan ts = endDay - starDay;

        progressBar1.Visible = true;
        progressBar1.Value = 0;
        progressBar1.Minimum = 0;
        progressBar1.Maximum = ts.Days;

        while (tmpDay <= endDay)
        {
            FileName = textBox2.Text + "\\" + tmpDay.ToString("yyMMdd") + "14.000";
                            //读取单个文件数据(1.2万个)
            TData = Red_T(SurfaceInfo, FileName,tmpDay.ToString("yyyyMMdd"));
            label3.Text = tmpDay.ToString("yyyy-MM-dd");
            //输出数据
            FileName = "最低气温数据.txt";
            StreamWriter sw1 = new StreamWriter(System.Environment.CurrentDirectory + "\\" + FileName, true, System.Text.Encoding.Default);
            tmpStr = "";
            for (int i = 0; i < TData.GetLength(0); i++)
            {
                tmpStr = tmpStr  + TData[i]+ "\t";
            }                
            tmpStr = tmpStr + "\r\n";
            sw1.Write(tmpStr);
            sw1.Close();

            tmpDay = tmpDay.AddDays(1);
            if(progressBar1.Value + 1<=progressBar1.Maximum)
            {
                progressBar1.Value = progressBar1.Value + 1;
            }

        }
        progressBar1.Value = 0;
        MessageBox.Show("计算完成");

    }

1个回答

devmiao
devmiao   Ds   Rxr 2016.09.26 01:06
Csdn user default icon
上传中...
上传图片
插入图片