问题描述
我有一个非常简单的.Net Micro Framework LED项目(在ARM Cortex-M4 CPU上的netmf 4.2 GHI代码上运行).这是相关代码:
I have a very simple .Net Micro Framework LED project (running on netmf 4.2 GHI code on an ARM Cortex-M4 CPU). Here is the relevant code:
using Microsoft.SPOT.Hardware;
[…]
OutputPort _RedLED;
OutputPort _GreenLED;
OutputPort _BlueLED;
[…]
_RedLED = new OutputPort(GHI.Hardware.FEZCerb.Pin.PB15, false);
_GreenLED = new OutputPort(GHI.Hardware.FEZCerb.Pin.PB14, false);
_BlueLED = new OutputPort(GHI.Hardware.FEZCerb.Pin.PB13, false);
[…]
for (var i = 0; i < numTimes; i++)
{
Debug.Print("Go white ...");
_RedLED.Write(true);
_GreenLED.Write(true);
_BlueLED.Write(true);
Thread.Sleep(2000);
Debug.Print("Go dark ...");
_RedLED.Write(false);
_GreenLED.Write(false);
_BlueLED.Write(false);
Thread.Sleep(2000);
Debug.Print("Go red ...");
_RedLED.Write(true);
Thread.Sleep(2000);
_RedLED.Write(false);
Debug.Print("Go green ...");
_GreenLED.Write(true);
Thread.Sleep(2000);
_GreenLED.Write(false);
Debug.Print("Go blue ...");
_BlueLED.Write(true);
Thread.Sleep(2000);
_BlueLED.Write(false);
}
当我在设备上运行代码时,LED会按预期方式点亮和熄灭,但会显示Visual Studio 2013中的输出窗口
When I run the code on the device the LEDs come on and off as expected but the output window in Visual Studio 2013 shows
Go white ...
Go red ...
Go green ...
Go blue ...
Go white ...
Go dark ...
Go red ...
Go blue ...
Go red ...
Go green ...
为什么不是所有的调试语句都能通过? Thread.Sleep使用的是错误的模式"吗?
Why aren't all the debug statements making it through? Is Thread.Sleep the wrong 'pattern' to use?
推荐答案
您的Thread.Sleep()函数仅影响程序的主线程.由于netmf程序只有一个线程,因此没有明显的原因可以捕获输出中的同步移位.在调试模式下,IDE本身使用的另一个线程有可能导致此结果.不过,您成功编译的netmf代码应该可以在嵌入式设备或仿真器上以正确的顺序正常工作.
Your Thread.Sleep() function only affects the program's main thread. Since netmf program has a single thread, there is no apparent reason to catch a synchronization shift in output. It is possible that in debugging mode, another thread that utilized by IDE itself, causes this result. Though, your successfully compiled netmf code should be working without a problem in correct order on embedded device or emulator.
这篇关于调试语句仅在.Net Micro Framework简单LED项目中间歇触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!