Zhuangkh

A .Net Developer

.Net Dotnet related


ConfigureAwait的使用

ConfigureAwait的使用 Task.ConfigureAwait(bool)指示了Awaiter完成任务时是否尝试将结果返回原上下文中继续执行,Ture为尝试返回,False则相反。 在讨论ConfigureAwait的正确使用场景之前,则应该先了解SynchronizationContext类型。 SynchronizationContext SynchronizationContext提供了在同步模型中传播上下文的基本功能,其中Send()方法将一个同步消息调度到一个上下文中,Post()方法将一个异步委托调度到一个上下文中。 例如,WinForms具有一个SynchronizationContext的派生类型,它重写了Post方法,以完成相当于Control.BeginInvoke的功能;这意味着对它的Post方法的任何调用都将导致委托稍后在该Control的UI线程上被调 …

.Net Task SynchronizationContext

WPF : Validation

Validation Rule 简单示例 class ViewModel { public int Number { get; set; } } TextBox TextBox.Text Binding Path=Number UpdateSourceTrigger=PropertyChanged Delay=200 /Binding /TextBox.Text /TextBox 示例中由于绑定的属性Number是int型(int在绑定到界面上时会自动添加int⇋string的converter),所以当我们输入非数字时,converter抛出的转换异常会被捕获到,此时Textbox上会出现红色边框。 异常被捕获 描述错误的实际消息存储在 System.Windows.Controls.ValidationError 对象的 …

.Net WPF Validation

Reading Revit File Without Revit

Starting the main Revit program needs to be accompanied by loading multiple components, which usually takes a long time. This is especially annoying after the file automatically calls the wrong version of Revit! So is there any way to read the Revit program without opening Revit? It should be clear that it will be very difficult not to read or modify member information in Revit (there may be …

Revit Ole Storage COM Structured Storage

Merge Multiple .Net Assemblies Into One

When we use a lot of external dependencies, the generated folder may contain a lot of Dlls that are not conducive to distribution. Before Here are two ways to pack multiple assemblies into one. Costura.Fody Costura is an add-in for Fody. Fody is an extensible tool for weaving .net assemblies. It enables the manipulating the IL of an assembly as part of a build. Costura is easy to use. Install …

.Net IL Merge Fody

WPF基础Ⅱ: 依赖属性

依赖属性 与.Net属性对比: 更高效 支持附加功能 更改通知 属性值继承 创建依赖属性 /// summary /// 只能为依赖对象添加依赖属性 /// /summary public class DependencyClass : DependencyObject { /// summary /// 定义依赖属性 /// 约定俗成命名规则:属性名+Property /// /summary public static readonly DependencyProperty NumberProperty = DependencyProperty.Register(//注册依赖属性 Number, //属性名 typeof(int), //属性类型 …

.Net WPF

WPF基础Ⅰ: XAML文件

基础 XAML单位 一个设备无关单位被定义为1/96英寸 标准Windows dpi为96 dpi 设备无关单位 * 系统dpi = 实际像素数 (eg: 1/96英寸 * 96dpi =1像素) XAML命名空间 使用特殊特性 xmlns 声明命名空间 命名空间可使用XML名称空间或者**.Net名称空间** # XML名称空间 使用URI xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml # .Net名称空间 使用类的完整名称 xmlns:Prefix=clr-namespace:Namespace;assembly=AssemblyName XAML属性 简单属性 可直接设置属性值 Grid …

.Net WPF

Generate a True Metafile in .NET

A few days ago when I was building the MS-OLEDS file for AutoCAD, I needed to create a Metafile as part of it. However, I encountered some small problems when using the built-in API. The Problem with Built-in API In System.Drawing.Imaging has a Metafile Class that allows us do a sequence of graphics operations on it.Here is my code and the test file in the HEX editor. public static void …

.Net Metafile

.Net MD5算法与系统FIPS兼容性

使用dotNet框架自带的Md5加密MD5CryptoServiceProvider时,在部分电脑上会出现InvalidOperationException. System.InvalidOperationException: 此实现不是 Windows 平台 FIPS 验证的加密算法的一部分。 在 System.Security.Cryptography.MD5CryptoServiceProvider..ctor() 出现的原因是系统启用了FIPS兼容算法,而FIPS标准并不支持MD5,所以当框架中的MD5算法调用系统的加密模块时就会爆异常. FIPS 140-2 defines security standards that the United States and Canadian governments use to validate security levels …

.Net MD5

  • 1