I'm having trouble working out why the following code doesn't catch the exception. It's my first go with Async in F# so I'm sure it's something simple
open System
open Microsoft.WindowsAzure
open Microsoft.WindowsAzure.StorageClient
open System.Windows.Forms
let mutable connection = "UseDevelopmentStorage=true;DevelopmentStorageProxyUri=http://ipv4.fiddler"
CloudStorageAccount.SetConfigurationSettingPublisher(fun cName cPublisher ->
cPublisher.Invoke connection |> ignore)
let storageAccount = CloudStorageAccount.Parse connection
let createTable tableName =
let client = storageAccount.CreateCloudTableClient()
async{
try
do! Async.FromBeginEnd(tableName, client.BeginCreateTable , client.EndCreateTable)
MessageBox.Show "Created" |>ignore
with
| :? StorageClientException -> printfn "failed"; MessageBox.Show("failed to create table") |> ignore
| _ -> printfn "Failed with unknown exception"
} |> Async.Start
[<EntryPoint; STAThread>]
let main(args) =
let form = new Form()
let btn = new Button(Text = "Click")
btn.Click.AddHandler(fun _ _ -> createTable "SomeNewTable")
form.Controls.Add btn
let result = form.ShowDialog()
0
If I run this and the table has already been created it says that an exception of type StorageClientException was not handled in the code, specifically pointing at the client.EndCreateTable part of the FromBeginEnd call
This smells like an issue that was fixed in FSharp.Core in VS2010 SP1. The .NET SynchronizationContext
s changed their behavior (in .NET 4.0 SP1, I think), and we needed a corresponding change in the F# runtime for async's to properly deal with the thread affinity.
I think you can grab the newer FSharp.Core here: http://www.microsoft.com/download/en/details.aspx?DisplayLang=en&id=15834
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With