Thread

Category:
Parallel
Description: This sample spawns threads at background. Please check the thread output at the background Console window.
Code:
let ParallelSample1() = 
// What will execute on each thread
let threadBody() =
for i in 1 .. 5 do
// Wait 1/10 of a second
Thread.Sleep(100)
printfn "[Thread %d] %d..."
Thread.CurrentThread.ManagedThreadId
i

let spawnThread() =
let thread = new Thread(threadBody)
thread.Start()

printfn "please check the background console window for output"

// Spawn a couple of threads at once
spawnThread()
spawnThread()

Execution Result:
please check the background console window for output

Last edited Sep 14, 2011 at 3:30 AM by ttliu2000, version 1

Comments

No comments yet.