Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Async/await for compact framework v3.5 - manual implementation

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

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.

like image 240
David Avatar asked Jun 24 '13 07:06

David


2 Answers

You can use Visual Studio 2015 to compile to Compact Framework 3.5 by following the instructions below:

  • Install the '.NET Compact Framework 3.5 Redistributable';
  • Copy files from 'C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE';
  • Paste the files at 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework' directory;
  • Create a directory named 'RedistList';
  • Create a file named 'FrameworkList.xml' at 'RedistList' directory;
  • 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 NETStandard.WindowsCE package.

An example project can be found at: https://github.com/WindowsCE/System.Collections.Immutable

Disclaimer: I'm the author of the package and the project above.

like image 106
Skarllot Avatar answered Oct 22 '22 22:10

Skarllot


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.

like image 23
svick Avatar answered Oct 22 '22 21:10

svick