Home > Net >  How async_await method added to the event
How async_await method added to the event

Time:10-13

Is an event:
 
The public event EventHandler ItemSelected;

The default add method is like this:
 
ListViewMenu. ItemSelected +=async (sender, e)=& gt;
{
If (e.S electedItem==null)
return;

Var id=(int) ((HomeMenuItem) e.S electedItem). The id;
Await RootPage. NavigateFromMenu (id);
};

I want to change a name, suggesting the return value is not correct, the return method is a Task of asynchronous synchronization method is void,
If I don't want the event to sync, that should be how to write
 
ListViewMenu. ItemSelected +=new EventHandler (ListViewMenu_ItemSelected);
Private async Task ListViewMenu_ItemSelected (object sender, SelectedItemChangedEventArgs e)
{
If (e.S electedItem==null)
return;

Var id=(int) ((HomeMenuItem) e.S electedItem). The id;
Await RootPage. NavigateFromMenu (id);
}
  •  Tags:  
  • C#
  • Related