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
Post a Comment