ドット ネット プロジェクトからの印刷をスレッドとしてのバックグラウンド作業として実行したいので、最初に各出力文字列を次のような文字列のコレクションに収集します。
myOutputStringCollection.Add(str);
次に、プリンターに送信するすべての行を収集した後、スレッドを実行する次のようなコードを記述します。
public static void printAllLines()
{
Thread t = new Thread(sendToPrinter);
t.Start(); //starts the thread
}
プリンター機能への送信は次のようになります。
public static void sendToPrinter()
{
int count = myOutputStringCollection.Count;
string[] myArray = new string[count];
myOutputStringCollection.CopyTo(myArray, 0);
for (int i = 0; i < count; i++)
{
SendStringToPrinter(myArray[i].ToString());
}
Array.Clear(myArray, 0, myArray.Length);
}
ここで直面している問題は、印刷ボタンを複数回クリックするとすぐに印刷の位置合わせが正しくないことです。スレッドの実行を適切に処理すれば、問題ないと思います。