Run async method 8 times in parallel

I coded it in the assumption that asynchronous and parallel processing would be the same Asynchronous processing and parallel processing are quite different. If you don’t understand the difference, I think you should first read more about it (for example what is the relation between Asynchronous and parallel programming in c#?). Now, what you want … Read more

Memory usage in C#

If you want the memory of the entire running process and not on a per thread basis, how about: // get the current process Process currentProcess = System.Diagnostics.Process.GetCurrentProcess(); // get the physical mem usage long totalBytesOfMemoryUsed = currentProcess.WorkingSet64; There’s a whole host of other process memory properties besides WorkingSet64 check out the “memory related” ones … Read more

How to Print Preview when using a DocumentPaginator to print?

So I got it working after reading Pro WPF in C# 2008 (Page 726). Basically the DocumentViewer class needs an XPS file to present a print preview of it. So I do the following: PrintDialog dialog = new PrintDialog(); var paginator = new RowPaginator(rowsToPrint) { PageSize = new Size(dialog.PrintableAreaWidth, dialog.PrintableAreaHeight) }; string tempFileName = System.IO.Path.GetTempFileName(); … Read more

IDictionary contravariance?

Firstly, covariance and contravariance in C# only apply to interfaces and delegates. So your question is really about IDictionary<TKey,TValue>. With that out of the way, it’s simplest to just remember that an interface can only be co/contra-variant if all values of a type parameter are either only passed in, or only passed out. For example … Read more