Async/await for compact framework v3.5
I have to develop an application for WinCE 5.0 which communicates/synchronizes data with a regular PC application which offers a webservice I can talk to with my mobile (industrial) device.
Since it is obvious to result in code which is hard to maintain on the mobile device side (check connection → when completed: check webservice availability → when completed: check whether mobile device is eligible for syncing → when completed start exchanging data) I would love to use the syncronous way of programming using await
s.
I have found some code snippet by Daniel Grunwald which is a minimal implementation of the stuff needed by the compiler for the async/await feature. Together with Task Parallel Library for .Net 3.5 (which I had to change just slightly because some methods called do not exist with the signature required) which implements the Task type for instance, it looks promising.
So far the solution does not build, because I'm lacking the implementation of TaskCompletionSource
. I decompiled the recent mscorlib with ILSpy, but the code is not usable - too many types in usage which are not present in CF.
At this point I am wondering whether this project is bound to fail, because I will never convince VS 2008 (which I have to use in ordner to target smart devices) to use the C# 5 compiler (maybe there is a workaround?), or CF is lacking crucial types for TaskCompletionSource (which I probably will need since I want to make events awaitable), or that TPL3.5 + Grunwald's snippet + TCS implementation will build but never actually work.
Can someone more experienced please appraise my intent? Would love to hear your comments, ideas and alternative approaches. Thanks.
Update Aaron Stainback's post indicates it should be possible to build CF 3.5 with VS2012. That should tackle at least the compiler issue.
I think that adding support for async
- await
to a platform that doesn't natively support it should be doable, because that's exactly what Microsoft.Bcl.Async does for .Net 4.0.
But using async
- await
requires compiler that supports it, there is no way around that. That means VS 2012 or possibly VS 2010 with the Async CTP (but I wouldn't recommend that, it's not production quality). As far as I know, there is no way to make this work with VS 2008.
One more possibility would be to use Mono, but I have no idea if it supports WinCE.
You can use Visual Studio 2015 to compile to Compact Framework 3.5 by following the instructions below:
Set the follwing content to the file created:
<?xml version="1.0" encoding="utf-8"?>
<FileList Redist="Net35-CF" Name=".NET Compact Framework 3.5">
</FileList>
Now you can create a .NET Core Class Library project on Visual Studio 2015 and target 'net35-cf' framework.
To use async/await you can use the System.Threading.Tasks.WindowsCE package.
An example project can be found at: https://github.com/WindowsCE/System.Collections.Concurrent/tree/08669ca5b45cc5c74c8c225a633828f9e26b5276
Disclaimer: I'm the author of the package and the project above.
链接地址: http://www.djcxy.com/p/14500.html上一篇: 不可变的类和特征?
下一篇: 异步/等待的紧凑框架v3.5