我在输出到文本块时遇到问题。基本上我做的是这样的:
private void ReadData()
{
double dHeading = 0;
int iHeading = 0;
String sString = "";
while (!stop)
{
//Get Heading
result = fsuipc.FSUIPC_Read(0x0580, 4, ref token, ref dwResult);
result = fsuipc.FSUIPC_Process(ref dwResult);
result = fsuipc.FSUIPC_Get(ref token, ref dwResult);
dHeading = dwResult;
if (dHeading != 0)
{
dHeading = dHeading * 360 / (65536.0 * 65536.0);
iHeading = Convert.ToInt32(dHeading);
}
if (iHeading < 0)
{
iHeading = 360 + Convert.ToInt32(dHeading);
}
if (iHeading == 0)
{
iHeading = 360;
}
if (result == true && iHeading < 10)
{
sString = "00" + Convert.ToString(iHeading);
}
if (result == true && iHeading >= 10 && iHeading < 100)
{
sString = "0" + Convert.ToString(iHeading);
}
if (result == true && iHeading >= 100)
{
sString = Convert.ToString(iHeading);
}
txbHeading.Text = sString;
// But if I change this line to MessageBox.Show(sString);
// it works fine.
}
}
程序冻结了,我对此无能为力。我必须在 VS 中停止它。如果我将 txbHeading.Text = sString 更改为 MessageBox.Show(sString),它工作正常。
请注意,我刚开始使用 C#。提前致谢!