One shot events using Lambda in C#

前端 未结 8 1630
無奈伤痛
無奈伤痛 2021-01-31 07:55

I find myself doing this sort of thing quite often:-

 EventHandler eh = null;  //can\'t assign lambda directly since it uses eh
 eh = (s, args) =>
 {
     //s         


        
8条回答
  •  温柔的废话
    2021-01-31 08:27

    You probably want to work with the new async/await idioms. Usually when I need to execute an event handler one-shot like you described, what I really need is something like:

    await variableOfSomeSort.SomeMethodAsync();
    //small snippet of code here
    

提交回复
热议问题