Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create a Thread in a portable class library?

F# code targeted for xbox360 using xna does not compile after I convert the project to a portable class library.

let thread = Thread(fun () ->
    setAffinity()

Thread gets red squiggles and the error message says

Error 1 This type has no accessible object constructors

Sure enough, if I look at mscorlib in the object explorer, the type has no constructor. Yet according to MSDN the constructor exists on xbox and in the PCL.

Edit: I tried with a C# PCL, and I got the same error.

like image 448
Joh Avatar asked Apr 28 '12 12:04

Joh


2 Answers

Creating threads is not portable. Your link is wrong, it doesn't talk about PCL.

This is the cost of using the Portable Class Library, it is what's left over after subtracting everything that isn't supported by at least one of the possible targets. Which doesn't leave much, the PCL is quite small. The biggest hang-up is a target that isn't actually mentioned as supported, yet, WinRT (aka Metro). It has a severely restricted api.

Consider ThreadPool.QueueUserWorkItem() instead. I assume that Task is going to be supported some day in the PCL. It is a work in progress right now.

like image 152
Hans Passant Avatar answered Sep 30 '22 10:09

Hans Passant


Not to be glib but this sounds like a bug and that's how I would proceed. Send it to fsbugs at Microsoft dot com

like image 31
Onorio Catenacci Avatar answered Sep 30 '22 09:09

Onorio Catenacci