Search code examples
.netportable-class-library

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.


Solution

  • 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.