Click here to Skip to main content
15,891,033 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: 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 
On the contrary after some practice with async methods you will see how they simplify all your code, not the opposite. Added bonus code after await is in the initial thread, when possible.

One downside of async method is that they don't take out/ref parameter.
But if you want the event args, here is another version that return the event
C#
public static Task<GpsLocationArgs> WaitForLocationChangedAsync(this IGps gps)
{
    var res = new TaskCompletionSource<GpsLocationArgs>();
    EventHandler<GpsLocation> eh = null;
    eh = (o, e) =>
    {
        gps.LocationChanged -= eh;
        res.TrySetResult(e);
    };
    gps.LocationChanged += eh;
    return res.Task;
}
// ....
var loc = await myGps.WaitForLocationChangedAsync();
Console.WriteLine($"({loc.Latitude}, {loc.Longitude})");

sadly, as I complained, it is NOT possible to write a general purpose WaitForEvent() method.. Cry | :((

But give it a go, maybe using some LINQ expression magic and some reflection you can come up with a reasonably easy and elegant version....
A new .NET Serializer
All in one Menu-Ribbon Bar
Taking over the world since 1371!

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 
GeneralRe: C# syntax I wish for Pin
Super Lloyd27-Sep-16 2:21
Super Lloyd27-Sep-16 2:21 
GeneralRe: C# syntax I wish for Pin
Shuqian Ying26-Sep-16 22:42
Shuqian Ying26-Sep-16 22:42 
GeneralRe: C# syntax I wish for Pin
Super Lloyd27-Sep-16 2:22
Super Lloyd27-Sep-16 2:22 
GeneralRe: C# syntax I wish for Pin
Member 1052748428-Sep-16 19:19
Member 1052748428-Sep-16 19:19 
GeneralRe: C# syntax I wish for Pin
Super Lloyd28-Sep-16 21:06
Super Lloyd28-Sep-16 21:06 
GeneralKeyboards Pin
milo-xml26-Sep-16 9:49
professionalmilo-xml26-Sep-16 9:49 
GeneralRe: Keyboards Pin
User 842026-Sep-16 10:04
User 842026-Sep-16 10:04 
GeneralRe: Keyboards Pin
milo-xml26-Sep-16 10:11
professionalmilo-xml26-Sep-16 10:11 
GeneralRe: Keyboards Pin
Clifford Nelson26-Sep-16 10:25
Clifford Nelson26-Sep-16 10:25 
GeneralRe: Keyboards Pin
milo-xml27-Sep-16 1:13
professionalmilo-xml27-Sep-16 1:13 
GeneralRe: Keyboards Pin
Clifford Nelson27-Sep-16 4:44
Clifford Nelson27-Sep-16 4:44 
GeneralRe: Keyboards Pin
David Crow26-Sep-16 10:30
David Crow26-Sep-16 10:30 

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.