*N Async, the next generation
Aug 10, 2016
In the previous installment, I discussed how to use iterators (yield return
) to create async methods. This time, we’re about to do almost the opposite – use async methods to implement async iterators.
In the previous installment, I discussed how to use iterators (yield return
) to create async methods. This time, we’re about to do almost the opposite – use async methods to implement async iterators.
TL;DR Just grab the .snk from the Roslyn repo, name your bridge assembly to something from the InternalsVisibleTo (e.g. Roslyn.Hosting.Diagnostics), sign it with the key, and you can access all the internals at compile time, with IntelliSense!
I have been waiting for while for the Roslyn team to expose the completion and signature help services so I could use them in RoslynPad without having to compile my own version. This was expected to be included in Update 1 but got pushed back.
If you’re using async/await a lot (a given nowadays), you may have noticed stack traces are not very readable. For example, this is a 3 async method chain’s stack:
Update
With Service Fabric SDK v2 this became much simpler. Check out this SO answer of mine for details.
Windows PerfMon is an invaluable tool, but it’s UI remained the same for years, stuck somewhere in the 1990’s. This is my attempt at “reimagining” it.
I recently found out that using the Microsoft.Bcl.Async package to support async/await in Silverlight has a major downside – it rethrows exceptions without preserving the stack trace. That’s because Silverlight lacks ExceptionDispatchInfo, a mechanism that was added in .NET 4.5 that allows rethrowing exceptions while keeping their stack traces intact.
When awaiting tasks in C#, you have the option to configure how the continuation behaves - whether it uses the Synchronization Context or not.
One of my clients recently needed to hook up a USB barcode reader to their app. Input from the reader needed to be redirected and handled by a special service, and ignored by the rest of the application. WPF has a property named Device in its KeyEventArgs class, but unfortunately it turns out that it uses the same instance for all input devices hooked up to the PC.
I’ve recently attended Microsoft’s Build conference in San Francisco, and I wanted to share some of my experiences.
One of the goals in concurrent programming is to reduce contention. Contention is created when two (or more) threads contend for a shared resource. The performance of synchronization mechanisms can vary considerably between contended and uncontended cases.
Hosting WCF services in AppFabric has its benefits, but it can cause a lot of pain as well. I was trying to resolve the following error which kept appearing at one of my customers:
WPF enables you to develop great looking applications very fast. But sometimes with this rapid approach one can overlook an important aspect - performance. It’s very common for developers to look into UI performance last, especially in LOB applications, but performance can have a significant effect on how professional your application is perceived to be.
Last month I gave a series of lectures in various campuses around Israel about Windows Phone and Azure.
In WCF we can use the APM pattern to create an asynchronous client. For example, consider the following service contract:
You’ve all read about the asynchrony promise of C# 5 (if you haven’t, I highly recommend reading Eric Lippert’s series about the subject or this post won’t make much sense). I think it’s a great step forward, and it would make asynchronous programming all a lot easier.
Pivot is a Microsoft Silverlight control which can visualize collections of data, filter and sort them in a very appealing manner. To see what I mean, check out the CodeValue Blogs Pivot:
Today I’m saying goodbye to Sela. I’ve been a senior consultant at Sela for the past 9 months, and it has been a good experience for me; I’m much more experienced with giving lectures and teaching classes. I’ve also had a chance to meet and work with some of the leading experts in their fields.
A few months ago I’ve decided to write a Prism tutorial by building a WPF UI for the .NET Reflector.
I’ve prepared a class diagram for my students of main WPF controls, divided into Decorators, Panels, Content Controls and Items Controls. The diagram was generated using the new Visual Studio 2010 Visualization and Modeling Tools (with a bit of manual cleanup).
One of the new features in .NET 4.0 is Side-By-Side In-Process (SxS InProc) execution of older CLRs (e.g. .NET 2.0). Previously, SxS was supported only in different processes. If you look it up, you’ll find these two (yet to be updated) blog posts by the CLR team, an MSDN Magazine article as well as one in the MSDN Library. You can get a good review of supported scenarios and some code, but what they all sorely lack is a working sample. (Update: There’s a new detailed article from the CLR team.)
I recently attended the Microsoft MIX10 conference in Las Vegas. I had a nice time, but mostly because of the location; Las Vegas is an interesting place. The conference itself was mainly a PR for the new Windows Phone, but there were a couple of very interesting lectures I would like to share:
Josh Reuben and I will be giving a lecture in the upcoming Sela Developer Practice about .NET Numerical Computing and Scaling Up (DSE502). It is intended to be a swift yet exhaustive review of what’s available out there for .NET developers. We will cover topics such as Cloud Computing, Infer.NET, GPGPU, Axum and StreamInsight. Should be pretty interesting.
If you’re writing a custom control in WPF, you may have encountered a very annoying bug: if you set the value of a DependencyProperty in your implementation code, the local value will trump any changes that you may try to apply to this property using bindings, styles, etc. You can read more about this in this post in Vincent Sibal’s blog.
One of the most referenced posts in this blog is the one dealing with the ClearType issues. Those of you who shared my pain will be glad to hear that Microsoft has delivered on its promise: WPF is getting a new text rendering stack in v4, which has the ability to render ClearType (and even aliased text) in every scenario. The new stack is also supposed to match the GDI text renderer, which means that small text will be much more readable.
I always prefer simpler solutions. The solution I proposed on my previous post was not that simple, and was not complete. It may still be useful for other stuff, but for the purpose of preserving ClearType while using DWM, I just have to admit it has too many issues.
WPF has ClearType issues. Hopefully some of them will be solved in the upcoming .NET 4.0. Meanwhile, however, I have concocted a nifty solution to one of the scenarios – placing stuff on the Aero Glass DWM frame.
The past 24 hours have been a blogger’s nightmare for me. I wanted to upgrade my GoDaddy’s hosting account to IIS 7. Unfortunately, they do not have any upgrade option, so you have to call their customer service, cancel your current hosting account, create a new one and build everything from scratch.
One of the most popular posts in this blog is the one explaining how to override the system theme and get the Vista look on non-Vista systems. This is possible because WPF ships with the theme files for all operation systems (well, all Microsoft OSs that WPF works on, i.e. XP, XP Media Center and Vista) and due to the fact that WPF doesn’t really use the system resources to get the OS theme, but rather relies on a private implementation of them that resides in the PresentationFramework.{Classic, Luna, Royale, Aero} assemblies.
I’ve released a new version of WPF Contrib (October 2008, although it’s released in November. I changed the release name a few times, so I decided to leave it like that. I’m only late by a few days…
First of all, you didn’t miss part one. Just thought it was a funny reference.
id: 178 title: License date: 2008-10-26T15:54:00+00:00 author: Eli Arbel layout: post redirect_from:
All code in this blog (unless noted otherwise) is released under the MIT license.
I’ve been using InteropBitmap in my GdiTextBlock. The control creates a new GDI+ Bitmap every measure pass, which it then converts to a WPF BitmapSource using the Imaging.CreateBitmapSourceFromHBitmap() method (this method returns an InteropBitmap).
In my previous post I mentioned the new Zune 3.0 visualizations. I really liked them, so I decided to try and create them using WPF’s new (3.5 SP1) Effects.
I’m loving the new Zune 3.0 client software. V1 was terrible. Just an ugly version of Windows Media Player. V2 was completely rewritten using a Microsoft internal platform called UIX, which is based on Media Center. Although it’s still .NET, I was slightly disappointed they didn’t use WPF.
It’s been a while since I’ve done anything with GDI+ (i.e. System.Drawing). System.Windows (i.e. WPF) is so much more powerful.
LINQPad is a very useful code snippet IDE. I use it all the time to test small pieces of code. It’s much more convenient than opening a new Visual Studio console application. It also formats the results very nicely.
One of the things C# generics lacks (compared to C++ templates) is specialization (neither explicit nor partial). This can be very useful in some cases where you want to perform something differently for a specific T
in a Class<T>
.
I’ve been quiet for a while. Working a lot, and also burning the midnight oil, trying to bring life into this project I call… the WPF Contrib.
Have you ever used EventManager.RegisterClassHandler()? If so, make sure you know what you’re doing. This method allows you to listen to events passing through (as I like to put it) an element (i.e. bubbling or tunneling), regardless of the class that invoked the call. Most of the times you would call it in a static constructor, and pass it a typeof of that class, but that is only a recommendation. The documentation is a bit weak on this point.
In WPF, like most UI frameworks, UI elements can only be updated from the thread they were created on. If you do background work, and want to affect the UI from a different thread, you’ll have to dispatch it. The Dispatcher class has a CheckAccess() method (which is marked as EditorBrowsableState.Never, making it invisible to intellisense for some reason.)
You can do really neat things with Bitmap Effects in WPF. Shadow, Bevel, Outer Glow can all have a great impact on how your application looks. But you should be aware that they don’t come cheap. They are rendered in software, which yields very poor performance. Also, ClearType is turned off on elements that have them applied, so your text becomes blurry.
WPF has a separate ClearType rendering system, which is better than GDI’s (mostly because it also does y-direction antialiasing; read more here and in the WPF Text Blog.)
First – great news. .NET Framework 3.0 has finally been released. Get it now!
Update: This utility has become a bit irrelevant since Reflector now has a BAML Viewer add-in. You can use it to view any assembly containing BAML resources, which it will automatically decompile into XAML.
WPF comes with a few theme assemblies, one for each Windows theme (Luna, Royale and Aero and the fallback theme, Classic.) Usually the theme is loaded according to your current system theme, but if you want to create a consistent look for your application, you may want to force-load a specific one.
It’s a fairly uncommon scenario to want to animate a type that’s not already built into WPF. But when you do, it takes quite a lot of work, mostly hacking it with Reflector to explore this undocumented venue.
I’ve been toying around with the CTP for a couple of days. There are some very nice stuff to see, and everything seems to be much smoother and faster (beside the setup, that is; I tried a clean install – which took over an hour – and an upgrade from Windows XP [first available in this CTP] – which took well over three hours…)
I’ve posted my “PDC 4 Free” contest entry. It’s a game of Monopoly where you can play as your favorite PDC lecturer (such as Bill Gates :) Wish me luck!
I’ve decided to replace P# with a great C# SWI-Prolog Interface, written by Uwe Lesta (I changed it a bit. See attachment.) The main reason for this decision was performance. P# was considerably slower, and the project had to meet certain standards.
I’ve finally decided on a Prolog project: the game Connect 4. I’m writing the GUI in VC# Express and using P# as the Prolog engine. I’ll probably also write a text version using SWI-Prolog. Here’s a screenshot of what I’ve come up with so far:
Well, it’s not perfect, but it may be useful to some.
I’ve just seen a blog entry about C# generics, concerning C#’s lack of typedefs. Actually, C# has a way of aliasing classes, using the using directive:
Apparently there’s a new API method, Application.EnableRTLMirroring(), in the next version of the framework, which is supposed to handle the mirroring in Windows Forms for you.
I’ve been working on a mirrored RTL (right-to-left) version of Lutz Roeder’s great CommandBar control for Windows Forms. There’s one problem left, which I haven’t solved yet, so I’d appreciate any comment on the matter.
Microsoft finally announced the winners in the DYCTII contest (I got tired of writing the full name :). But they only mentioned the first two winning categories, so I’m not there : | . Anyway, is there anyone interested in buying my VS.NET Enterprise Developer? |
I won 3rd prize in the Microsoft “Does Your Code Think In Ink?” contest: Visual Studio .NET 2003 Enterprise Developer and a one year subscription to PC Magazine.