hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Async stuff with .NET 4.0

Last post 06-08-2009, 4:05 by markhneedham. 0 replies.
Sort Posts: Previous Next
  •  06-08-2009, 4:05 10826

    Async stuff with .NET 4.0

    I'm playing around with some of the Async work flows from the Real World Functional Programming book and although they work fine with FSI 1.9.6.2 on .NET 2.0 I'm struggling to get it to work on FSI 1.9.6.16 on .NET 4.0

    This is the code:

    open System.IO
    open System.Net
    open Microsoft.FSharp.Control
        
    let downloadUrl(url:string) = async {           
         let req = HttpWebRequest.Create(url)
         let! resp = req.AsyncGetResponse()           
         let stream = resp.GetResponseStream()
         use reader = new StreamReader(stream)       
         return! reader.AsyncReadToEnd() }      

    let downloadTask = downloadUrl("http://www.manning.com");; 

    And then to run it on .NET 2.0 I use

    Async.Run(downloadTask, 10000);;

    And for .NET 4.0

    Async.RunSynchronously(downloadTask, 10000);;

    The former works fine and it prints the Manning website page to the screen but the later times out.

    Any ideas?

    Cheers,
    Mark

    Mark Needham
    Application Developer, ThoughtWorks
    http://www.markhneedham.com/blog
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems