WinRT demystified
tirania.org
tirania.org
public sealed class AddTwo {
public int Add (int a, int b)
{
return a + b;
}
public async IAsyncOperation SubAsync (int a, int b)
{
return a - await (CountEveryBitByHand (b));
}
}
Sorry for being an idiot here, but.. does this example make any sense to anyone else? There's a method that adds two numbers, but the async operation is SubAsync which subtracts something passed through CountEveryBitByHand from a... passed through something called await? Is this obvious to other people? Does he mean that any sealed class automatically becomes a component, so the AddTwo part is just the Add method? What does "a component that adds 2" mean anyway?Is it a joke and I'm not getting it?
To keep it simple they should have left out the second method.
Unless I'm incredibly wrong!
I suspect that code is contained in a class library project. Aka, generates a DLL. So no, not all sealed classes will be components.
The second method is there to illustrate what asynchronous programming will look like in C# 5. Native support for async is THE big feature in C# 5. The "await" allows you to call slow blocking code without a thorny nest of callbacks. There's some magic behind await. You can find out more on Google. Miguel could've definitely left out the SubAsync method in this example for clarity.
A component that adds 2 means a DLL that exposes the methods Add and SubAsync. In WinRT, you can code libraries in C# and use them in C++. Or Javascript.
int Add(int a, int b) { return a + b; }
int Sub(int a, int b) { return a - CountEveryBitByHand(b); }
So, I guess the example is just to show the async stuff, really.The await keyword is a new one in C# 5 which halts execution until the promise is fulfilled. Then execution is resumed from that point, and the expression can be evaluated and the function returns.
It's similar to how inlineCallbacks in Twisted work, if you're familiar with those.
Tasks - http://msdn.microsoft.com/en-us/library/system.threading.tas....
When you use C# and VB, you are using the full .NET
framework. But they have chosen to expose a smaller
subset of the API to developers to push the new vision
for Windows 8.
For me, this is a really interesting point that this article doesn't fully get. When you use WinRT you might be using the C# compiler, CLR runtime and .NET string & collection classes, but there are huge sections of the .NET BCL that now look like a lame duck. WinRT is the new way to do XML, JSON, HTTP, networking, security, globalisation, threading, printing... (more here: http://msdn.microsoft.com/en-us/library/windows/apps/br21137...)You can still use the full .NET class library when doing ASP.NET, but who wants to use different JSON classes for App development vs. Web development? Won't the WinRT version gradually become the preferred way of doing JSON in both environments, with the .NET BCL existing to fill in the server side only gaps?
My suspicion is that .NET 5 will merge the two.
Asynchronous API that will really make a difference for the end user, right? There won't be any more waiting for UI to unfreeze :)
Even the use cases that are not covered by the two keywords, like fetching a whole bunch of stuff together or issuing a lot of requests and having the data trickle in as they are completed one by one are handled easily with the Task API, to the point where you have WhenAny and WhenAll methods and you just do "await Task.WhenAll(tasks)".
http://channel9.msdn.com/Events/BUILD/BUILD2011/BPS-1004
It shows just how much attention to detail Microsoft has put into the UX design of Metro and Windows 8. Can't wait to see the finished product.
The design aside (which is an entire topic on its own), some of the functionality decisions like contracts just make you wonder why the sodding hell didn't we have these sooner. I mean there's the half-baked drag and drop handler than no one actually bothers to implement even when it makes absolute sense to do so, and that's it. Being able to pull things out of a web service from the file picker, on the other hand, just makes me go "I want this yesterday."
I'm curious to know, how will the review application be able to catch your use of the private API through reflection? It seems like a pretty hard problem that could be a big security risk if done incorrectly.
and Javascript uses promises and "then ()".
What is "then ()"? Have they created their own wacky fork of Javascript? Javascript already handles asynchronous programming (feel free to argue that is doesn't do it "right" or even "well"), so why extend the language? promise.then(callback)
so: var p = doSomethingAsync();
p.then(function () { alert("hello"); })No changes to async programming at all, events and continuations as always.
- no normal RTSP support. Ok, I used libav (working hard to wrap it, cause it's a well written C library, but not trivial to use from C#)
- I get h264 frames that I need to look at before decoding. No way to give compressed h264 frames to WPF to decode. (So I use libav again). SilverLight actually does have MediaStreamSource -- but this is not a SilverLight app.
- Ok, so let's try to use the hardware decoder when it's there. libav supports it, yay! What about WPF? Well, no. You have to use Direct3D (?) to get a surface to draw on. With no way to do this from C# (Interop fails badly according to a DirectShow+Direct3D MVP I consulted). I give up, and use libav's software decoder.
- Ok, I have a bitmap, I want to blit it quickly to the screen - WTF? The only way to do it is use a Shared Memory section (interop again) to create a bitmapsource; then update the underlying memory.
- Except memory runs out after about 20 seconds (~400 frames) of .Invalidate() calls. WTF? Turns out it's a known bug introduced in v4 (wasn't there in v3.5). No fix yet. Just call GC.Collect() after every invalidate. Yay for "automatic" garbage collection!
- Ok, so now we have got a reasonable video. What about sound? Everyone with experience I know says "use NSound" (which is interop again). I opt for interopping with winmm, which I have experience from the C++ side.
- Now, to wrap it all together, I need a millisecond-precision timer. Sorry, no go in .net; Winmm's "timeBeginPeriod" to the rescue! but .net's Dispatcher still triggers my code every 15ms. WTF? I would be happier with a 100us timer, which windows doesn't even provide, but I can't get less than 15000us!
I'm so sorry we chose .NET; it seems to cater well to CRUD type applications, but it is so inadequate for everything I tried to do with it, that it's not even funny.
There hasn't been a single time when the answer to some deficiency was not "Well, this version of Windows/.NET is cr*p, but the next one is going to be perfect for every need".
I didn't choose to go with C# for this project - someone else did. Being the low-level guru, I was called in to fix all the deficiencies.
Really, .NET has been out for 10 years now, WPF for 5. There is no excuse for this abysmal level of support, and until I see Win8 actually working properly with sample code that addresses stuff such as I mentioned above, I won't consider it.
I agree it's meant for C++ on Windows (if it is meant for Windows at all - the 15ms timer precision thing runs so deep it bites in many places you wouldn't expect).
But Microsoft and MS fanboys keep touting that "C# is all you need to get things done" - that has never been the case, and I expect it not to be the case with WinRT either.
You get correct RTSP support, h264 decoding, hardware acceleration for decoding, DirectSound audio output and resampling.
Thanks for VLC, btw! It's awesome!
If by access to framebuffers, you mean getting the raw images in a buffer, yes you can.
http://msdn.microsoft.com/en-us/library/windows/apps/hh45275...