C# 如何在微框架中实现中断?

C# 如何在微框架中实现中断?,c#,.net-micro-framework,C#,.net Micro Framework,我无法使用VS2010在.NET中编译stm32f4discovery的代码 使用NETMF 4.2 using System; using System.Threading; using Microsoft.SPOT; using Microsoft.SPOT.Hardware; namespace MFConsoleApplication1 { public class Program {

我无法使用VS2010在.NET中编译
stm32f4discovery
的代码

使用
NETMF 4.2

    using System;
    using System.Threading;
    using Microsoft.SPOT;
    using Microsoft.SPOT.Hardware;

    namespace MFConsoleApplication1
    {

        public class Program
        {
            private static InterruptPort interruptPort;

            public static void Main()
            {
                interruptPort =  new InterruptPort(Cpu.Pin.GPIO_Pin2,
                                               false,
                                               Port.ResistorMode.PullUp,
                                               rt.InterruptMode.InterruptEdgeLevelLow);

                interruptPort.OnInterrupt += new NativeEventHandler(port_OnInterrupt);


                 Thread.Sleep(Timeout.Infinite);
            }


             private static void port_OnInterrupt(uint port, uint state, TimeSpan time)
             {
                Debug.Print("Pin=" + port + " State=" + state + " Time=" + time);
                interruptPort.ClearInterrupt();
             }
         }
    } 
编译时,我收到以下错误:
port\u OnInterrupt的重载与委托“Microsoft.SPOT.Hardware.NativeEventHandler”匹配。

如何编译代码


我从《Expert.NET Micro framework》一书中选取了这个例子。

尽管文档中指出最后一个参数是
TimeSpan
,但我认为它确实是我一直使用的.NET microframeworks中的
DateTime

所以不是

 private static void port_OnInterrupt(uint port, uint state, TimeSpan time)
 interruptPort.OnInterrupt += new NativeEventHandler(port_OnInterrupt);
试一试

还有一个提示:代替

 private static void port_OnInterrupt(uint port, uint state, TimeSpan time)
 interruptPort.OnInterrupt += new NativeEventHandler(port_OnInterrupt);
你可以写

 interruptPort.OnInterrupt += port_OnInterrupt;

这是等效的,但更具可读性。

从文档中看,它应该可以工作。Timespan确实是一个奇怪的参数选择。