Click here to Skip to main content
15,892,005 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: MQOTD Pin
RossMW26-Sep-16 22:07
professionalRossMW26-Sep-16 22:07 
GeneralRe: MQOTD Pin
Johnny J.26-Sep-16 22:11
professionalJohnny J.26-Sep-16 22:11 
GeneralRe: MQOTD Pin
U. G. Leander26-Sep-16 22:11
professionalU. G. Leander26-Sep-16 22:11 
GeneralRe: MQOTD Pin
Daniel Pfeffer26-Sep-16 22:45
professionalDaniel Pfeffer26-Sep-16 22:45 
GeneralRe: MQOTD Pin
Herman<T>.Instance26-Sep-16 22:56
Herman<T>.Instance26-Sep-16 22:56 
GeneralRe: MQOTD Pin
Corporal Agarn27-Sep-16 3:11
professionalCorporal Agarn27-Sep-16 3:11 
GeneralThat's all we need! Pin
Johnny J.26-Sep-16 21:16
professionalJohnny J.26-Sep-16 21:16 
GeneralC# syntax I wish for Pin
Super Lloyd26-Sep-16 17:33
Super Lloyd26-Sep-16 17:33 
Not sure where to post that, (there might some sort of MSDN link somewhere) for now I just post there.

"Sometimes" one has to wait for an event to be triggered (once) and then do something, I'd like to write a WaitForEvent() method. Unfortunately, due to the particular of event syntax, I can't and I have to write one wait for that event method for every single event I am interested in!... Cry | :((

Mmm... case for a code sinppet me just think! OMG | :OMG: Shucks | :-\ Roll eyes | :rolleyes:

In any case here is the syntax for a specific event:
C#
Task WaitForThatEventAsync(Foo source)
{
    var res = new TaskCompletionSource<bool>();
    EventHandler eh = null;
    eh = (o, e) =>
    {
        source.ThatEvent -= eh;
        res.TrySetResult(true);
    };
    source.ThatEvent += eh;
    return res.Task;
}

EDIT
My explanation seem confusing.. another explanation is that I would like to be able to write a "general purpose" WaitForEvent() extension method

that transform this cluncky code
C#
EventHandler ev = null;
ev = (o, e) => {
  source.Event -= eh;
  DoSomething();
};
source.Event += eh;

into this elegant code
C#
await source.Event.WaitForEvent()
DoSomething();

where both do the exact same thing!
Sadly this is not possible right now... I have a to write a new WaitForThatEvent() method for each event I am interested in... Cry | :(( but it would be cool. Would make ReactiveC# better looking too.
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!


modified 27-Sep-16 3:02am.

GeneralRe: C# syntax I wish for Pin
BillWoodruff26-Sep-16 17:40
professionalBillWoodruff26-Sep-16 17:40 
GeneralRe: C# syntax I wish for Pin
Rage26-Sep-16 18:11
professionalRage26-Sep-16 18:11 
GeneralRe: C# syntax I wish for Pin
Super Lloyd26-Sep-16 20:11
Super Lloyd26-Sep-16 20:11 
GeneralRe: C# syntax I wish for Pin
BillWoodruff27-Sep-16 3:49
professionalBillWoodruff27-Sep-16 3:49 
GeneralRe: C# syntax I wish for Pin
Pete O'Hanlon26-Sep-16 19:44
mvePete O'Hanlon26-Sep-16 19:44 
GeneralRe: C# syntax I wish for Pin
Super Lloyd26-Sep-16 20:08
Super Lloyd26-Sep-16 20:08 
GeneralRe: C# syntax I wish for Pin
Pete O'Hanlon26-Sep-16 20:22
mvePete O'Hanlon26-Sep-16 20:22 
GeneralRe: C# syntax I wish for Pin
Super Lloyd26-Sep-16 20:51
Super Lloyd26-Sep-16 20:51 
GeneralRe: C# syntax I wish for Pin
Anurag Gandhi26-Sep-16 20:36
professionalAnurag Gandhi26-Sep-16 20:36 
AnswerRe: C# syntax I wish for Pin
Super Lloyd26-Sep-16 20:57
Super Lloyd26-Sep-16 20:57 
GeneralRe: C# syntax I wish for Pin
Anurag Gandhi26-Sep-16 21:19
professionalAnurag Gandhi26-Sep-16 21:19 
GeneralRe: C# syntax I wish for Pin
Super Lloyd26-Sep-16 21:30
Super Lloyd26-Sep-16 21:30 
GeneralRe: C# syntax I wish for Pin
Yortw28-Sep-16 11:12
Yortw28-Sep-16 11:12 
PraiseRe: C# syntax I wish for Pin
Super Lloyd28-Sep-16 13:55
Super Lloyd28-Sep-16 13:55 
GeneralRe: C# syntax I wish for Pin
Yortw28-Sep-16 13:57
Yortw28-Sep-16 13:57 
GeneralRe: C# syntax I wish for Pin
Pete O'Hanlon26-Sep-16 22:02
mvePete O'Hanlon26-Sep-16 22:02 
GeneralRe: C# syntax I wish for Pin
BillWoodruff27-Sep-16 1:02
professionalBillWoodruff27-Sep-16 1:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.