Advertisement
Guest User

Oleg Orlov

a guest
Dec 14th, 2013
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 1.23 KB | None | 0 0
  1. open System
  2. open System.Net
  3. open Microsoft.FSharp.Control.WebExtensions
  4. open System.Windows.Forms
  5.  
  6. let form = new Form()
  7. let text = new Label()
  8. let button = new Button()
  9.  
  10. let urlList = [ "Microsoft.com", "http://www.microsoft.com/"
  11.                 "MSDN", "http://msdn.microsoft.com/"
  12.                 "Bing", "http://www.bing.com"
  13.               ]
  14.  
  15. let fetchAsync(name, url:string) =
  16.     async {
  17.         try
  18.             let uri = new System.Uri(url)
  19.             let webClient = new WebClient()
  20.             let! html = webClient.AsyncDownloadString(uri)
  21.             text.Text <- String.Format("Read %d characters for %s", html.Length, name)
  22.         with
  23.             | ex -> printfn "%s" (ex.Message);
  24.     }
  25.  
  26. let runAll() =
  27.     urlList
  28.     |> Seq.map fetchAsync
  29.     |> Async.Parallel
  30.     |> Async.RunSynchronously
  31.     |> ignore
  32.  
  33. form.Width  <- 400
  34. form.Height <- 300
  35. form.Visible <- true
  36. form.Text <- "Test download tool"
  37.  
  38. text.Width <- 200
  39. text.Height <- 50
  40. text.Top <- 0
  41. text.Left <- 0
  42. form.Controls.Add(text)
  43.  
  44. button.Text <- "click me"
  45. button.Top <- text.Height
  46. button.Left <- 0
  47. button.Click |> Event.add(fun sender -> runAll() |> ignore)
  48. form.Controls.Add(button)
  49.  
  50. [<STAThread>]
  51. do Application.Run(form)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement