开发者

How to call an event from another event

I have an event like static private void HandleClientEventCB(SPD.SPD_eventType type, SPD.SPD_event this_event, object passback) in a class public class SPURTServer, I need to call this event outside another event Here the '**SPD_eventType**' is enumeration under different project that means 'namespace Spo.S开发者_StackOverflow社区PDlib' and 'public class SPD' here the value for that enum is SPD_clientEvent = 5,

and SPD.SPD_event is a struct like public struct SPD_event and passback value is null.

So I called like this in outside event like shown below

SPURTServer.HandleClientEventCB(Spo.SPDlib.SPD.SPD_eventType.SPD_clientEvent, Spo.SPDlib.SPD.SPD_event,object passback);

but it is throwing error like "Invalid expression term 'object'" I am not sure what about the other two arguements. Can anybody guide me here?


In your call, you need to remove the word Object.

so:

SPURTServer.HandleClientEventCB(Spo.SPDlib.SPD.SPD_eventType.SPD_clientEvent,
    Spo.SPDlib.SPD.SPD_event,
    passback);

or cast it:

SPURTServer.HandleClientEventCB(Spo.SPDlib.SPD.SPD_eventType.SPD_clientEvent,
    Spo.SPDlib.SPD.SPD_event,
    (object)passback);

Assuming that passback is a valid object in the scope of the call.

Edit: based on the comments below:

What you're doing is passing the type of the event, not an instance of the event itself.

SPD_Event is a definition of your data, but you have created an instance of it.

You'd need to to something like

var newEvent = new Spo.SPDlib.SPD.SPD_event();
newEvent.WhatEverProperties = whatNeedsToBeSet;

SPURTServer.HandleClientEventCB(Spo.SPDlib.SPD.SPD_eventType.SPD_clientEvent,
    newEvent,
    null);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜