开发者

F# Asynch thread problem

I am learning F# and very interested in this language

I try to create async expression to run asynchronously.

for 开发者_JAVA百科example

let prop1=async{ 
    for i=0 to 1000000 do  ()
       MessageBox.Show("Done")
    }

let prop2=async{ 
    for i=0 to 1000000 do  ()
       MessageBox.Show("Done2")
    }

Async.Start(prop1)
Async.Start(prop2)

when i run the program, i got that there are thread amount increasing of program process, from 6 to 8 , when i done close 2 message box , the process seem not destroy those created threads , the count also 8 , what happened or i got misunderstand about F# asynchronous

Thank for your help


The threads are taken from a thread pool (which is why there are more threads than actions, incidentally).

The pool exists until the application terminates.

Nothing to worry about

Edit For a nice in-depth article on F#, async and ThreadPool: http://www.voyce.com/index.php/2011/05/27/fsharp-async-plays-well-with-others/


The runtime might use a thread pool, that is threads are not destroyed, but waiting for another asynchronous tasks. This technique helps the runtime reduce time to start a new async. operation, because creating a new thread might consume some time and resources.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜