Showing posts with label dotnet4. Show all posts
Showing posts with label dotnet4. Show all posts

Tuesday, 29 June 2021

Distributed Caching Options in .NET

There are a number of distributing caching options in .NET.

Ignoring the distributed aspect of our desired cache for the minute we focus on the inbuilt MemoryCache.

For an in-process, in-memory cache, one option is to use MemoryCache (System.Runtime.Caching). Caching data types were introduced in .NET 4. A CacheItemPolicy dictates how long objects remain in the cache and what the eviction policy is.

Some more flexible and specialized options are:

Microsoft.Extensions.Caching.SqlServer

Microsoft.Extensions.Caching.StackExchangeRedis

NCache.Microsoft.Extensions.Caching.OpenSource

Sunday, 22 May 2016

The MEF as an Integral Part of .NET 4 and an Important Part of .NET 4.5

The Managed Extensibility Framework (MEF) was introduced in .NET 4. It is supported by the MEF "composition engine". Its main namespace is System.ComponentModel.Composition.

Thursday, 26 November 2015

What does it mean to "Embed Interop Types"?

As of .NET 4, the CLR supports embedding type information for COM types direct into managed assemblies, rather than requiring managed assemblies to request COM types via Interop assemblies. The embedded type information is usage-based, it will omit methods and types that are not used by Monsieur Managed Assembly. The feature is used to simplify deployment.

Wednesday, 19 February 2014

.NET Transparency Model ("Security Silo" Model) Overrules CAS as of Dot Net 4

Transparency separates code running as part of an application from code running as part of infrastructure. Transaparent code can only "do things" within the bounds of a permission set, and can't do funky things with infrastructure (running critical code etc.). This follows the principle of least privilege.

Saturday, 23 November 2013

An Alternative to Threads: Tasks in Task Parallel Library

.NET 4 introduces an alternative to Threads, known as Tasks, which is part of mscorlib. This is the new and preferred way to do asynchronous programming in .NET.

Task factories are the new tool of choice to create Tasks (the new incarnation of Threads) and start them immediately. They can also be used to create task continuations. A continuation task is a task that invokes another task on completion. The task that completes before the next task is called is known as the antecedent.

A task can be created using the syntax:  Task.Factory.StartNew( () => ...).

The above syntax says we must supply a delegate as a lambda expression a.k.a. anonymous function, or object of type Action, to the StartNew method of the Factory object (default instance of TaskFactory).

The StartNew method returns an object of type Task.  Task.WaitAll takes a list of tasks and blocks until all the tasks specified have completed. It can be called with an optional extra argument, specifying the wating time timeout in milliseconds (stored as an Int32, implemented as a struct in mscorlib, though you already knew that).

Because now we are talking about tasks not threads, we can no longer talk about multithreading, and to talk about multitasking seems rather an over-use of the term. Therefore, we need a new term, and for that we have been given the new conjunction, Task parallelism. 

Friday, 22 November 2013

Asynchronous Programming in a Pre and Post Dot Net 4 World

Dot net 4 recommends using Tasks over Threads. But what vestiges of the pre-dot net four programming universe retain their relevance in the "dot-net four and above" programming world? For that we must turn to the interfaces of System.Threading.

IAsyncResult emerged as early as Dot net 1.1 in Visual Basic, C# and Managed C++, literally as the "return type of methods that implement an asynchronous operation". An IAsyncResult has a property AsyncState that contains information about the asynchronous operation. The boolean IsCompleted indicates whether the operation has completed.

Tuesday, 5 November 2013

.NET 4 Security Model Acknowledges Mistakes were Made with CAS

.NET 4 changed *many* aspects of the .NET security model. One important change was the reducing the complexity of Code Access Security (CAS) by shifting responsibilities from the runtime to the developers. This certainly impacted code using Assembly.Load in System.Reflection (thank you mscorlib!)

The .NET Security Blog is definitely worth revisiting from time to time to get the latest download on .NET Security design decisions.

Wednesday, 26 September 2012

PFX (Parallel Extensions) built on System.Threading.Tasks

What is PFX? (I heard about it on Channel 9).

PFX stands for Parallel Extensions for the .NET framework (released in .NET 4.0) and is something of increasing importance, judging from the multiple references to PFX on channel9.msdn.com. This post will be a primer to PFX - getting you up-to-speed with the basic terminology and concepts.

Who developed PFX?

Both Microsoft Research and the CLR team were involved in the development of PFX.

Two Parts to PFX and their Relationship

First is Parallel LINQ (PLINQ) and second is Task Parallel Library (TPL). PLINQ uses TPL for execution. The other technical term is CDS which stands for coordination data structures - used to synchronise and co-ordinate execution of concurrent tasks.

Example

using System.Threading.Tasks;
Parallel.ForEach(myListOfStrings, s => Console.WriteLine(s));

Data Structures for Parallel Programming

More can be found here. Ex: System.Collections.Concurrent.ConcurrrentDictionary<Key,Value>