I have an F# class library as such:
namespace FsharpTestSystem
open System
open System.IO
open TCLoggerEntity
open TCIQuoteEntity
type TestCallback() =
member this.LoggerOutput() = Logger.Info("F#")
member this.OnQuote(q : TCQuote) = Console.WriteLine(q.ToString())
Adding a reference of this F# assembly into a C# project, I have tested that I can call LoggerOutput fine from C#. However, if I try to have C# event callback execute in F# I get an error on the line below:
From C#:
using FsharpTestSystem;
public delegate void QuoteChangeEvent(TCQuote q);
event QuoteChangeEvent OnQuoteChange;
TestCallback fsts = new TestCallback();
api.MAPI.OnQuoteChange += fsts.OnQuote(); // this doesn't work
fsts.LoggerOutput(); // This works fine
you are invoking your method, which would try and use whatever OnQuote returned as the event handler.
OnQuote is the event handler, so try :-
api.MAPI.OnQuoteChange += fsts.OnQuote;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.