This again?

Windows Central Podcast 37: Windows 10 Mobile is still dead

Redefining the PC

Why Microsoft's Surface phone could be MUCH more than a mere 'phone'

Surface Pwn 5

Surface Pro 5, Project NEON details leaked on LinkedIn?

XP-YESSSSSSS

Dell's already awesome XPS 15 gets even better in 2017

Surface table meets Windows 10

Yes, we did put Windows 10 on the original Surface table ... and it rocks

Cream o' the crop

Before buying a Microsoft laptop, check out our pick for the absolute best

Simple and secure, just the way I like it

We think Windows 10 Cloud is a great idea, here's why

uber micro

Halo Wars 2 has something for everyone. Here's our full review.

Oldie but goldie

We reviewed Microsoft's decade-old Surface table

Creators Update comin' at ya

These are the coolest new features in the next big Xbox One update (video)

Buyer's guide

The Razer Blade 14 is the best laptop Razer has to offer

Windows 10 app gems

10 terrific Windows 10 apps you should be using

Tower of power

Here's what we think of Dell's XPS Tower Special Edition

Quite a deal

Grab the complete C# coding bootcamp for $41!

Your go-to laptop guide

Introducing our ultimate laptop buyer's guide

Listen here

Attn Android and iPhone users: What you need to know about Windows phone

Old is new?

The original Surface Pro still holds its own in the 2-in-1 world

Xbox Greenlight?

No, internet, Microsoft isn't opening Xbox to all UWP games

Falling in love

HP Envy 34 review: An ultrawide curved all-in-one after my heart

2015 machine in 2017?

Surface 3 still holds its own in 2017

< >
Welcome to the Windows Central Forums Create Your Account or Ask a Question Answers in 5 minutes - no registration required!
Results 1 to 5 of 5
  1. praveen gadipelly's Avatar
    Member

    Posts
    1 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
       #1  
    Hi,


    I am using HttpWebRequest class for Rest Service call in Windows phone 7.1.I want to use the response of the call back function of service call .but before invoking call back function, next statement in the function that is calling service call is executing .Is there any solution for this?
  2. wenogg's Avatar
    Developer

    Posts
    51 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    #2  
    Check out the Async CTP. It allows you to use async/await. This should enable the behavior you are looking for.
  3. dotnetnelson's Avatar
    Developer

    Posts
    13 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    #3  
    You can use a ManualResetEvent to signal a thread to wait. Look it up on MSDN.

    Or if you do like above suggested then you can use async as follows:
    Code:
    await MyAsyncMethod().AsTask().Wait();
    Also: I'll note that synchronous calls are highly not recommended. You're much better chaining responses using async/await continuations.
  4. CommonBlob's Avatar
    Developer

    Posts
    160 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    #4  
    Quote Originally Posted by dotnetnelson View Post
    You can use a ManualResetEvent to signal a thread to wait. Look it up on MSDN.

    Or if you do like above suggested then you can use async as follows:
    Code:
    await MyAsyncMethod().AsTask().Wait();
    Also: I'll note that synchronous calls are highly not recommended. You're much better chaining responses using async/await continuations.
    Im a bit new to using await, but I highly recommend that method.
  5. dotnetnelson's Avatar
    Developer

    Posts
    13 Posts
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    #5  
    await is basically a shorthand for .ContinueWith( .. ) on a Task of T .

    Code:
    var result = await SomeAsyncFunction();
    MessageBox.Show(result.ToString());
    When you await SomeAsyncFunction() the method you're currently in immediately returns to the caller. Anything after "await" is chained up into a continuation of the asynchronous operation.

    So even though the code looks sequential, anything after "await XXX" will only execute once the asynchronous operation has completed. It allows your code to be less disjointed as a result.

    Also to note is that the thread your implicit continuation returns on is the same thread you awaited on. So if you await an async method on the UI thread, it will chain your continuation on the UI thread and do the async operation off thread.

    It basically saves some typing:

    Code:
    Task.Factory.StartNew<string>(() => { return SomeSyncOp(); }).ContinueWith(result => { MessageBox.Show(result) });
    Only my continuation doesn't do marshaling back to the UI thread.

Posting Permissions

";