日期:2014-05-17  浏览次数:20852 次

c#读写txt文件的问题
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DevelopLibrary.Enums;
using DevelopLibrary.DevelopAPI;
using System.IO;


namespace sellopen
{
    public class sell : EventStrategyBase
    {

        FuturesAccount fa = null;//定义一个策略生命周期的变量
        
StreamWriter outfile = null;


        public override void OnStart()//在策略启动时执行,一般用来创建图表,或读取账户信息。
        {
           
            outfile = new StreamWriter(@"e:\out2.txt");
          
        }

       

        public override void OnBarOpen()//如果是tick级的,比onTick事件晚一个tick.如果是其他级别,在一个Bar刚建立的时候执行。
        {
                      
            string str1 = Price + ","+LOW[LOW.Length - 2]+ ","+ "\r\n";
            outfile.WriteLine(str1);
           
         }
         
        
    }
}


请问这个怎么改成txt读写共享模式?就是程序在输出变量到txt时,允许txt被打开。现在好像只能在程序结束时才能打开txt。


然后第二个问题是,麻烦各位大哥帮我把读取txt格式写一下。



------解决方案--------------------
改用log4net吧
------解决方案--------------------
当一个流占用一个文件的时候,是无法被其他资源共享的吧
变通一个解决方案,用一个队列或其他的什么保存修改内容,再定时更新
或者及时关闭流,应该不难吧?
------解决方案--------------------