c# - How to capture return value for Event handler? -


environment: ms sql server, ef, wcf-ria-service, sliverlight

try define event async call complete event like:

public event eventhandler<int> mysavecomplete; 

the event call sp in db , return id value(int).

but got error message when try compile code:

the type 'int' cannot used type parameter 'teventargs' in generic type or method 'system.eventhandler'. there no boxing conversion 'int' 'system.eventargs'

how resolve problem?

eventhandler<t> requires generic argument of type eventargs (i.e. 1 inherited it). so, should create own class:

public class mysavecompleteeventargs : eventargs {     public mysavecompleteeventargs(int id)     {        id = id;     }      public int id { get; private set; } } 

and use eventhandler<t> argument:

public event eventhandler<mysavecompleteeventargs> mysavecomplete; 

event raising:

protected void onmysavecomplete(int id) {     if (mysavecomplete == null)         return;      mysavecomplete(this, new mysavecompleteeventargs(id)); } 

you can use action<int> delegate event type.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -