How To

Tasks are (still) not threads and async is not parallel

Paul Ballard

18 Sep , 2015  

 

 

I talk to a lot of developers who are either new to .NET or are moving from an older version to the newer platform and tools. As such I’m always trying to think of new ways to describe the nature of Tasks vs Threads and async vs parallel. Modern .NET development is steeped in the async/await model and async/await is built on the Task model. So understanding these concepts is key to long term success building apps in .NET.

In order to help visualize this I built a simple WPF application that displays a chart of an application’s activity. I want to display some of the potential variations in behavior of what appear to be a simple set of async tasks.

Take the following method

BW1

This is a simple event handler which is going to call 3 asynchronous methods and then wait for all three to complete and then print out how long it took to do the whole operation. How many threads are there? Some people will assume only 1, some will assume 3. Like everything in software, it depends.

The DoWorkAsync() method just runs a loop. Each time around the loop, it will do some sort of asynchronous task and then do some busy “work” for some amount of time, then it will draw a rectangle on the screen representing the time that it spent doing that “work.” (This is analogous to making a web service call and then doing some local processing on the data returned from the service.) In this way we can easily see (a) when the work is being performed, and (b) whether the work overlaps with other task’s work.… Read more

, , ,

News

Visual Studio Code Updated

Paul Ballard

13 Aug , 2015  

Microsoft has released an update to their multi-platform code editor Visual Studio Code.  This release brings improvements in documentation, PHP snippets, and support for Roslyn based quick fixes.

Documentation improvements include better organization and additional information about how to extend VS Code.

Since VS Code was released there have been a large number of questions around how to configure and customize the product. In part this was due to the fact we had not adequately listed out the available options in our documentation. To help address this we’ve:

  • Included the contents of the settings.json file in the Customization topic
  • Separated out key bindings into their own topic area

Beyond documentation, there were also a number of significant improvements made in support for editing different languages.  These include better HTML formatting, JSON formatting, and new common snippets for PHP.  For C#, improvements include quick fixes (aka lightbulbs) and upgraded OmniSharp support to 1.1.0.

Also fixed were the following defects:

  • 17915: VS Code crashes with large emberjs/es6/amd project
  • 17427: Git cannot be found if installed into a non-default location
  • 17947: Open with encoding Windows 866 doesn’t work
  • 18094: Wrong “duplicate identifier” error in node files when using “exports”*

For more information on this update, or to download the free Visual Studio Code editor visit the Updates Page.… Read more

, , ,

Humor

Evolution At Work?

Paul Ballard

7 Aug , 2015  

monkeys-typingRead more

, ,

Wintellect Blogs

Taming the SplitView Control in Windows 10

Jeff Prosise

30 Jul , 2015  

Of all the new controls featured in Windows 10, SplitView is perhaps the most emblematic. SplitView makes it easy to implement “hamburger menu” interfaces like the ones featured in Windows 10’s built-in News, Sports, and Photos apps, among others. A hamburger icon consisting of three horizontal bars sits atop a ribbon on the left side of the window. The ribbon contains iconic buttons, most of which navigate to another page in the app when clicked. Typically, but not always, clicking the hamburger icon expands the ribbon to reveal labels to the right of the icons. It’s an easy navigation pattern to learn, and even if somewhat controversial, it’s already familiar to users who have seen similar UI paradigms used in Web sites and mobile apps.

Most developers who set out to use SplitView for the first time are surprised at how lean it is. SplitView has little in the way of a default UI other than a pane that expands and collapses. There is no SplitViewItem class for placing buttons in a SplitView, and precious little guidance on how to implement them. Plus, incorporating a SplitView in your app requires some restructuring of the code that Visual Studio dumps into App.xaml.cs.… Read more

, , , , ,

Wintellect Blogs

Pooling Buffers for Better Memory Management

Sergio Loscialo

9 Jun , 2015  

Occasionally, you need a more robust solution to solve a problem.

In my last post, I wrote about the horrors of this small code snippet:

public byte[] Serialize(object o)
{
    using (var stream = new MemoryStream())
    {
        MySerializer.Serialize(stream, o);
        return stream.ToArray();
    }
}

One way to alleviate the memory pressure that can be caused by frequent creation and destruction of large objects is to tell the .Net garbage collector to compact the Large Object Heap (LOH) using:

GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;

However, this solution, while it may reduce the memory footprint of your application, does nothing to really solve the initial problem of allocating all that memory in the first place. As I mentioned in my last post, one way to accomplish that goal is to use a buffer pool.

The Buffer Manager

Instead of writing my own buffer manager, I am going to use the implementation Microsoft provides in the Windows Communication Framework (WCF) called the BufferManager. Now that WCF is open source you can go look at the implementation of BufferManager here.

The BufferManager essentially allocates a large chunk of contiguous memory and sets it aside for later use. You can create an instance of a BufferManager by calling the CreateBufferManager() static method as follows:

BufferManager.CreateBufferManager(maxPoolSize, maxBufferSize);

The first parameter, maxPoolSize represents how much memory you want the BufferManager to allocate in total.… Read more

, ,

Video

5 Questions with Kathleen Dollard

Paul Ballard

5 Jan , 2015   Video

In this interview with Kathleen Dollard we dig into some of the new features of Visual Studio 2015, what’s coming up in the C# language, and the power of Roslyn and what it means for developers.

Kathleen Dollard wants to teach you to code better. There’s more to learn about the tools you use every day and the tools you aren’t yet using. Coding is our passion and debugging is our challenge – you’ll be happier if you do both better. Kathleen’s written dozens of articles, spoken at conferences and user groups around the world, and pushes Microsoft to respond to your real world needs as a long time MVP. Her Open Source project RoslynDom offers alterative access to information in the .NET Compiler Platform, Roslyn with a load/interrogate/mutate/build SyntaxTree model. She has courses in the Pluralsight library and a series of C# 6 webcasts now available for free on WintellectNOW.… Read more

, ,

WintellectNOW

Sneak a Peak at the New Features in Visual Studio 14

Paul Ballard

4 Nov , 2014   Video

Learn about what’s new in Visual Studio with this excerpt from Kathleen Dollard’s course “What’s New in C# 6.0, Visual Basic .NET 14, and Visual Studio 14

Proper-case menus, touch capabilities, extract-method refactoring, code peeks, PerfTips, and more make Visual Studio 14 the most featured-filled version of Visual Studio ever. See them in action and amp up your programmer productivity… Read more

, ,

Resources

Jeffrey Richter’s Guide to Working with Azure Storage Tables via C# and other .NET Languages

Paul Ballard

12 Oct , 2013  

Jeffrey Richter has worked with Azure Storage Tables for years and acquired a lot of lessons along the way. Jeffrey Richter’s Guide to Working with Azure Storage Tables via C# and other .NET Languages shares with you those lessons learned and ways you can be more effective using Azure Storage Tables. In addition to the Guide, Jeffrey put together the Wintellect Azure Storage Library, available on NuGet, that you can use to improve your team’s productivity working with Azure Storage Tables.

Read more

,

Resources

Programming the Windows Runtime by Example, by Jeremy Likness and John Garland

Paul Ballard

12 Oct , 2013  

The most thorough hands-on guide the building Windows Store apps using C# and XAML. Written by Microsoft MVPs and Windows 8.1 experts Jeremy Likness and John Garland, this book provides over 80 sample projects that illustrate every aspect of the Windows Runtime (WinRT) from data, networking, and encryption to cloud services, globalization, packaging, and deployment.
Read more

,

Resources

Windows Runtime via C#, by Jeffrey Richter and Maarten van de Bospoort

Paul Ballard

12 Oct , 2013  

Get a thorough grounding in the Windows Runtime—and apply your C# skills to building innovative apps for the Windows Store. Guided by Jeff Richter, a recognized master of Windows programming, along with principal Windows consultant Maarten van de Bospoort, this book provides pragmatic guidance on the non-UI side of Windows development, and features a wealth of examples in Microsoft Visual C# 2012.


Read more

,