2009-05-24 59 views

回答

13

事件是不是我的專長,但這個例子似乎在F#1.9.6.16工作:

namespace EventExample 
open System 
type MyEventArgs(msg:string) = 
    inherit EventArgs() 
    member this.Message = msg 

type MyEventDelegate = delegate of obj * MyEventArgs -> unit 

type Foo() = 
    let ev = new Event<MyEventDelegate, MyEventArgs>() 

    member this.Ping(msg) = 
     ev.Trigger(this, new MyEventArgs(msg)) 

    [<CLIEvent>] 
    member this.GotPinged = ev.Publish 

參見

http://cs.hubfs.net/forums/thread/10555.aspx

+0

謝謝,它的工作原理:)請問如何做你知道CLIEventAttribute?我沒有在文檔/語言規範/谷歌的任何地方看到它...... – 2009-05-24 18:33:40