MailboxProcessor.TryScan<'Msg,'T> 方法 (F#)

更新:2010 年 9 月

通过按到达顺序浏览消息来扫描消息,直至提供的函数返回 Some 值为止。 其他消息保留在队列中。

命名空间/模块路径: Microsoft.FSharp.Control

程序集:FSharp.Core(在 FSharp.Core.dll 中)

// Signature:
member this.TryScan : ('Msg -> Async<'T> option) * ?int -> Async<'T option>

// Usage:
mailboxProcessor.TryScan (scanner)
mailboxProcessor.TryScan (scanner, timeout = timeout)

参数

  • scanner
    类型:'Msg -> Async<'T> option

    用于在跳过消息时返回 None 、 在处理消息并将其从队列中移除时返回 Some 的函数。

  • timeout
    类型:int

    可选超时(以毫秒为单位)。 默认值为 -1,它对应于 Infinite()。

返回值

scanner 脱离读取消息生成的异步计算(Async 对象)。

备注

如果给定超时并超过超时,则返回 None。 此方法可在代理的主体内使用。 对于每个代理至多只有一个并发读取器可处于活动状态,因此 ReceiveTryReceiveScan 或者 TryScan 中至多只有一个处于活动状态。 scanner 函数的正文在其执行期间被锁定,但会在执行异步工作流之前解锁。

平台

Windows 7、Windows Vista SP2、Windows XP SP3、Windows XP x64 SP2、Windows Server 2008 R2、Windows Server 2008 SP2、Windows Server 2003 SP2

版本信息

F# 运行时

受以下版本支持:2.0、4.0

Silverlight

受以下版本支持:3

请参见

参考

Control.MailboxProcessor<'Msg> 类 (F#)

Microsoft.FSharp.Control 命名空间 (F#)

修订记录

Date

修订记录

原因

2010 年 9 月

阐明了多线程行为。

信息补充。

2011 年 4 月

阐明了超时行为。

内容 Bug 修复