.net - Async.fromBeginEnd with WinForms Begin/EndInvoke -


i'm trying write async wrapper on top of function called listcontrols extracts list of forms controls starting root control. plan implement in terms of control.begininvoke, control.endinvoke , async.frombeginend

the code below:

type private listcontrols = delegate of unit -> control list  let asynclistcontrols (root:forms.control) : async<control list> =      let begininvoke (_, _) =          new listcontrols(fun () -> listcontrols root)         |> root.begininvoke      let endinvoke result =          root.endinvoke result :?> control list      async.frombeginend (begininvoke, endinvoke) 

the behavior i'm getting endinvoke never executed. knows doing wrong? there better approach?

edit

just make clear, computation executed async.runsynchronously.

also if replace code

/// code below reproduced memory , might not compile let asynclistcontrols (root:forms.control) : async<control list> =      let ctx = windowsformssynchronizationcontext.current      async {          do! async.switchtocontext ctx          return listcontrols root          do! async.switchtothreadpool ()      } 

...then seems work don't because of forced context switches , fact async computation supposed built on ui thread

async different task in doesn't start on creation. daniel pointed out, must explicitly start async using async.runsynchronously or other method.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -