TCP/IPで一連の値を送信する必要がある次のコードでは、各値が変数x、yおよびzを何らかの方法で変更します。応答が得られたら、コードに 'x'、 'y'、 'z'の現在の値を表示したいが、そうではない。私はスリープ()、タイマー、およびテキストボックスの代わりにラベルを使用してみましたが、何も追加しようとしませんでした。何か案は?よろしく変数の値が十分に速く表示されない
for (i = 0; i < cant; i++)
{
byte[] data = null;
aux = (Convert.ToInt32(v[i, 3] + 48, CultureInfo.InvariantCulture));
//update variables' values
x = x + Convert.ToInt32(v[i, 0]);
y = y + Convert.ToInt32(v[i, 1]);
z = z + Convert.ToInt32(v[i, 2]);
data = System.BitConverter.GetBytes(aux);
NetworkStream stream = client.GetStream();
// String to store the response ASCII representation.
String responseData = String.Empty;
// Send the message to the connected TcpServer.
stream.Write(data, 0, 1);
// Buffer to store the response bytes.
data = new Byte[256];
while (responseData.Length == 0)
{
// Read the first batch of the TcpServer response bytes.
Int32 bytes = stream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
}
//DISPLAY CURRENT VALUES
textBoxX.Text = x.ToString();
textBoxY.Text = y.ToString();
textBoxZ.Text = z.ToString();
}
これはWinformsやWPFの動作に非常に基本的なものです。コードが実行を停止してメッセージループを再入力するまで、コントロールは再描画されません。 WinFormsを想定すると、textBoxX.Update()を追加してペイントを強制することができます。実際にはあまり実用的ではありませんが、それを正しく実行すれば、人間の目にはぼやけたように見えます。すべての値を表示することが重要な場合は、代わりにListBoxを使用します。 –