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

2

8

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.

Antevert answered 24/6, 2013 at 7:35 Comment(2)
Hi David. I have written my own version of BackgroundWorker to implement on the Mobile devices we have. Parallel processing, however, requires a multi-core processor or it will only ever run in a single process anyway. Other than getting this to work as written, what is your goal?Botts
@jp2code: I wanted to build a maintainable project where it is easy to understand the cascading occurence of events required for special actions to be taken (see the part with → symbols). I guess I will go for a deterministic automaton to handle that - actually async/await gets transformed into nothing else than a FSM by the compiler. It would have been just awesome to find a way to "reuse" the already implemented mechanism and not to reinvent the wheel. Hope I haven't misunderstood your question.Antevert
K
2

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.

Kekkonen answered 24/6, 2013 at 8:28 Comment(0)
C
3

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.

Cheeky answered 27/6, 2017 at 15:36 Comment(0)
K
2

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.

Kekkonen answered 24/6, 2013 at 8:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.