I got an event from special API I'm working with, the event I'm working with is defined as
public event EventHandler<QuoteEventArgs> OnQuote
public class QuoteEventArgs : EventArgs
so what I'm trying to do is attach a method to run when I got a new Quote
listening to this event.
so what I do is:
myInstance.OnQuote += new EventHandler<QuoteEventArgs>(doThis);
And the method is defined as:
public void doThis(object sender, QuoteEventArgs e){
//code here..
}
The error I get is:
Cannot implicity convert type
'System.EventHandler<MT4API.QuoteEventArgs>'
to'System.EventHandler'
but I don't seem to have a special eventHandler on the API either, so not quite sure how to make that work.
From the comment discussion, it appears that you are using a version of the library in which the event does not have a generic type, ie the signature is
public event EventHandler OnQuote;
This means you will also have to consume it in a non-generic way:-
myInstance.OnQuote += new EventHandler(doThis);
public void doThis(object sender, EventArgs e){
var myArgs = (QuoteEventArgs)e;
...
}
My guess is that there are two classes with the name QuoteEventArgs
, perhaps one from a referenced DLL and one from a generated proxy. Ensure that if you've got usings that the usings are correct.
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.