基本的にDo..While
、テキストファイルのいくつかの行をループするループがあります。行を処理し、値(機能したかどうか)を返し、次の行に移動したいと思います。
ProcessTXT
2つの文字列を受け入れる という関数があります。Source
およびDestination
新しいファイルの。
結果にを設定しReturnedValue string =
、バックグラウンドワーカーに変数が変更されたかどうかを確認させる方法はありますか?もしそうなら、この値をリストボックスに追加しますか?
private void TranslatePOD(string strSource, string strDest,)
{
TextWriter tw = new StreamWriter(strDest);
TextReader tr = new StreamReader(strSource);
do
{
//My Code doing stuff
//Need to send a result somehow now, but i have more work to do in this loop
//Then using tw.writeline() to write my results to my new file
} while (tr.ReadLine() != null);
}
編集:Yieldを使用した現在のテストコード。私の出力は「TestingGround.Form1+d__0」です。私は何か間違ったことをしましたか?
namespace TestingGround
{
public partial class Form1 : Form
{
static IEnumerable<string> TestYield(string strSource)
{
TextReader tr = new StreamReader(strSource);
string strCurLine = System.String.Empty;
while ((strCurLine = tr.ReadLine()) != null)
{
yield return strCurLine;
}
}
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string MySource = System.String.Empty;
MySource = @"C:\PODTest\Export Script\Export\Shipment List.csv";
listBox1.Items.Add(TestYield(MySource));
}
}