我可以在F#PCL库中使用System.Timers.Timer吗?

我可以在F#PCL库中使用System.Timers.Timer吗?,f#,portable-class-library,F#,Portable Class Library,我需要在F#PCL库中使用System.Timers.Timer 我目前的目标是Framework4.5和Profile7(我使用了VS模板),它不允许访问System.Timer 据了解,这是一个已知问题,在4.5.1中解决 我创建了一个4.5.1 C#PCL并检查了它的.csproj。它以Framework4.6为目标,使用Profile32 有没有办法在F#项目中实现同样的目标?我天真地试图用C#值更新.fsproj,但它破坏了一切 非常感谢 主F#PCL配置文件中的System.Time

我需要在F#PCL库中使用
System.Timers.Timer

我目前的目标是Framework4.5和Profile7(我使用了VS模板),它不允许访问System.Timer

据了解,这是一个已知问题,在4.5.1中解决

我创建了一个4.5.1 C#PCL并检查了它的.csproj。它以Framework4.6为目标,使用Profile32

有没有办法在F#项目中实现同样的目标?我天真地试图用C#值更新.fsproj,但它破坏了一切


非常感谢

主F#PCL配置文件中的
System.Timers.Timer
(和
System.Threading.Timer
)类不起作用。考虑到支持普通的F#async,您可以通过编写自己的“计时器”类型轻松解决这一问题。例如,以下内容(虽然有点难看)应该能很好地模拟
定时器
类功能:

type PclTimer(interval, callback) = 
    let mb = new MailboxProcessor<bool>(fun inbox ->
            async { 
                let stop = ref false
                while not !stop do
                    // Sleep for our interval time
                    do! Async.Sleep interval

                    // Timers raise on threadpool threads - mimic that behavior here
                    do! Async.SwitchToThreadPool()
                    callback()

                    // Check for our stop message
                    let! msg = inbox.TryReceive(1)
                    stop := defaultArg msg false
            })

    member __.Start() = mb.Start()
    member __.Stop() = mb.Post true
类型PclTimer(间隔,回调)=
let mb=新邮箱处理器(有趣的收件箱->
异步{
让stop=ref false
而不是!停下来
//休息时间睡觉
do!异步。睡眠间隔
//计时器在线程池线程上启动-在这里模拟这种行为
do!Async.SwitchToThreadPool()
回调函数()
//查看我们的停止信息
let!msg=inbox.TryReceive(1)
停止:=defaultArg msg false
})
成员_uu.Start()=mb.Start()
成员_uu.Stop()=mb.Post true

Troy-您是否试图使用
系统计时器.Timer
(即:)?你需要用定时器做什么?它必须用定时器吗?您可以使用async或类似的方法来解决它,这在PCL7中确实有效……不,我不需要使用计时器。使用异步和递归对我来说是可行的,但是我遗漏了框架的哪些其他部分呢?:)定时器类(两个)是我知道的在配置文件中缺失的大类,但应该在那里…谢谢里德,你是一个明星!!