One Windows

Microsoft is building a new Windows 10 Shell for PC, Mobile and Xbox

Get ready for beta!

Halo Wars 2 Blitz: Game modes, beginner's tips, and more

On the Inside

Everything you need to know about the Xbox Insider Program

Beautiful compromises

Surface Studio review: you'll want one, even if you don't need one

3-in-1

Is this the Surface Phone? Microsoft awarded patents for foldable devices

Windows Central Offers

MCSE Certification bundle is just $39

Even more improvements

All the changes found in Windows 10 build 15007!

Games as a Service

What does the cancellation of Scalebound mean for future Xbox exclusives?

Windows Central Offers

Save $90 on these FRESHeBUDS Pro Magnetic Bluetooth Earbuds

Returning for 2017

We're back with an new episode of #AskDanWindows

Lifetime Subscription

VPNSecure is currently 91% off

Our favorite things

The Best of CES 2017 Awards

Infinity Edge in your hand

The XPS 13 2-in-1 is the Dell convertible we've always wanted

Project Valerie

Razer just made a laptop with three — THREE! — 17-inch 4K displays. 😱

Great design from Palo Alto

HP's CES 2017 releases are truly gorgeous PCs

Intel and Google's big day

CES 2017 Day Two: New laptops, new phones, and old ideas made new

Take five is better than ever

The updated Lenovo ThinkPad X1 packs Kaby Lake chips and zero bloatware

Everything we know about the next Xbox: Project Scorpio

UWPowered

'Game Mode' for Windows 10 will power Xbox One and Scorpio games too

Buyer's guide

Best accessories for Microsoft Surface Book

< >
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.    #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
    #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
    #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
    #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
    #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