BufferBlock<T> and TaskFactory in Silverlight
-
domingo, 31 de octubre de 2010 19:37
Hi,
Is there a reason System.Threading.Tasks.Task.Factory property to be marked as internal? I really need TaskFactory.FromAsync method. Also I need BufferBlock<T>, is it available for Silverlight? If not, do you plan to include those in the future release?
Thanks
Todas las respuestas
-
domingo, 31 de octubre de 2010 19:48Moderador
Hi Ziggo-
We're still determining what is the right surface area to include for Silverlight, and the surface area we included in the Async CTP is the minimal avenue we're considering (another is just to include all of the TPL surface area with nothing removed, and of course there are options in between). Including just the minimum helps us to figure out (with feedback like yours) what's really necessary for Silverlight so we can make sure that the appropriate surface area ends up shipping for real. It's good to know that FromAsync is important to you even in Silverlight. For our edification, are you looking to use FromAsync with methods in the .NET Framework, or are you looking to wrap other APM (Begin/End) implementations outside of the Framework? For now, you can approximate FromAsync on Silverlight with code like the following (this is basically what our implementation does). Consider wrapping Stream.BeginRead/EndRead:
public static Task ReadAsync(this Stream stream, byte [] buffer, int offset, int count) { var tcs = new TaskCompletionSource<int>(); stream.BeginRead(buffer, offset, count, iar => { try { tcs.SetResult(stream.EndRead(iar)); } catch(Exception exc) { tcs.SetException(exc); } }, null); return tcs.Task; }
Regarding BufferBlock<T>, we're not sure yet as to our Silverlight plans for System.Threading.Tasks.Dataflow.dll, but it's great to know you're interested in a Silverlight build. Can you share what you plan to do with it?
Thanks!
- Propuesto como respuesta Stephen Toub - MSFTMicrosoft Employee, Moderator domingo, 31 de octubre de 2010 19:48
- Marcado como respuesta Stephen Toub - MSFTMicrosoft Employee, Moderator domingo, 31 de octubre de 2010 23:18
-
martes, 02 de noviembre de 2010 15:04
Hi Stephen,
First off, i want to thank you for the quick reply! What I'm trying to do is converting my duplex service proxy class from the APM pattern to the new TAP pattern. I tried the proposed APM wrapping code and it seemed to work. Thank you. Regarding BufferBlock<T>, I saw the Producer/Consumer example in the document named "TPLDataflow" and I thought it might be useful for my proxy class. The proxy class is message based, so what I'm trying to achieve is when a message is received from the server it will be posted to the buffer and then asynchronously will be fetched from there with ReadAsync(). Do you think that this is a right way of using it? I'm still learning and I do not claim that I understand everything in deep.
Thanks

