Anduin Xue

let today = new Beginning();


UWP 一个技术上成功但商业上失败的框架之死;一个现代的操作系统究竟应该提供什么?

2023年初,我习惯性的打开UWP的Mail app,来收发一下日常Email。但是,令我遗憾的是,它已经建议我尝试新版Mail App了。 不出我所料,新的Windows自带的Mail app是网页套壳的,而不是UWP。这意味着微软自从VSCode和Teams的成功之后,在网页套壳的道路上越走越远。以至于将网页套壳的魔爪继续伸向Outlook。 我曾经在Windows 10发布之初,盼望着会有一天用上 UWP 的 Visual Studio,谁知等了数年,却用上了 exe 的 MSEdge 和 网页套壳的 Mail。 UWP 这个本是 Windows 最后一次技术上的变革已经宣告失败。但,我想在念它的悼词之前,或许还可以回顾这个框架的一生。它诞生时的野心、困难、逆天的技术变革、解决了大量的问题、新的平台等。 UWP 本是优秀的框架 如果一定要让我总结一下 UWP,我想最好的说法就是:成功 …

C# Microsoft Windows Microsoft Store UWP

Raise up Visual Studio Code correctly in your C# client-side program

When I search this topic from Google, I always get results with 'How to write C# program in VS Code'. But what I was working on is an editor, which allows the user to open VS Code to edit a folder. My UI is like this: So what should I do to open the folder in VSCode? Code is below: Process.Start(new ProcessStartInfo { UseShellExecute = true, // IMPORTANT: …


Validate an object in any C# projects

Sometimes, we need to check if the input is valid. Usually, we may do this: if (string.IsNullOrWhiteSpace(InputArgument.TargetMachine) || string.IsNullOrWhiteSpace(InputArgument.PatchId)) { throw new ArgumentException($"Invalid input argument! Patch ID: '{InputArgument.PatchId}', Target Machine: '{InputArgument.TargetMachine}'!");  …

ASP.NET Core C# .NET Validation

C# Play with GZip.

A extension class for string to add GZip features. Copy the following code to your project first. using System; using System.IO; using System.IO.Compression; using System.Text; public static class GZipExtensions { private static byte[] Zip(string str) { var bytes = Encoding.UTF8.GetBytes(str); using (var msi = new MemoryStream(  …

C# .NET Compress GZip Base64

Retry with exponetial back-off on C#

Just built a simple retry engine in C#. /// /// Retry engine. /// public class RetryEngine { private static Random rnd = new Random(); private readonly ILogger logger; /// /// Creates new retry engine. /// /// Logger public RetryEngine(  …

C# .NET Retry

Build a common cache service for your C# app.

Recently, I found that almost every time I creates a new .NET app, I gonna need cache service. While Microsoft officially provides the IMemoryCache, I found that it is pretty complicated for you to use it. For it requires a lot of code. So I wrapped it to a more common one. Before starting, make sure the project references Microsoft.Extensions.Caching.Memory and Microsoft.Extensions.Logging.  …

ASP.NET Core C# .NET Core Performance Caching .NET Cache MemoryCache

Programmatically connect to the remote server via SSH and execute remote command.

Recently I was trying to build a server management tool. That I need to connect to my server (Ubuntu) programmatically. I usually access my server via SSH, as a normal human. So I wanna do it with the same approach. First, create a new .NET Core project with: dotnet new console After creating the new project, install the latest SSH.NET library. Reference: NuGet Gallery | SSH.NET 2020.0.1 And  …

C# .NET Core bash Linux SSH

Use JetBrains code quality analyzer to prevent checking-in bad C# code

When we are using Azure DevOps to review PR, it's simple and easy to use. Usually, we only run tests and build tasks, like this: In my previous blog, I mentioned how to run test and generate code coverage for CI pipelines: Display code coverage information for .NET Core project using Azure DevOps. - Anduin Xue ( -------------- JetBrains ReSharper and Rider are impressive C# grammar  …

C# Azure DevOps JetBrains Resharper Code Quality Pipelines

C# run tasks in a threads pool with fixed size

Imagine I have 100 tasks to run. But my machine has only 16 core. So I expect that every core will run one task in parallel. And once a core is idle, assign a new task to it. That will be very easy for C# with Task. But before starting, we gonna create a thread-safe queue for saving our tasks. public class SafeQueue<T> { private readonly Queue<T> queue = new Queue&  …

C# Async Task Multi-Threading