随笔分类 -  .NET

.NET。
.NET:事务、并发、并发问题、事务隔离级别、锁等相关资料整理
摘要:这里面的有三篇文章,必须要读读:http://technet.microsoft.com/en-us/library/ms189130(v=sql.105).aspx。这里有一个系列,我还没有读:http://aboutsqlserver.com/2011/09/28/locking-in-microsoft-sql-server-table-of-content/。这里写的最实在:http://www.cnblogs.com/zhouqianhua/archive/2011/04/15/2017049.html#2797029。下面还有两篇没有来得及看的文章:http://erinstell 阅读全文

posted @ 2013-11-21 09:09 幸福框架 阅读(1148) 评论(0) 推荐(0) 编辑

.NET:CLR via C# User-Mode Constructs
摘要:The CLR guarantees that reads and writes to variables of the following data types are atomic: Boolean, Char, (S)Byte, (U)Int16, (U)Int32, (U)IntPtr, Single, and reference types. This means that all bytes within that variable are read from or written to all at once.Although atomic access to variable 阅读全文

posted @ 2013-11-17 10:36 幸福框架 阅读(642) 评论(0) 推荐(0) 编辑

.NET:CLR via C# The Interlocked Anything Pattern
摘要:Many people look at the Interlocked methods and wonder why Microsoft doesn't create a richer set of interlocked methods that can be used in a wider range of scenarios. For example, it would be nice if the Interlocked class offered Multiply, Divide, Minimum, Maximum, And, Or, Xor, and a bunch of 阅读全文

posted @ 2013-11-16 10:08 幸福框架 阅读(973) 评论(0) 推荐(0) 编辑

.NET:C# 如何实现的闭包?
摘要:背景C# 在编译器层面为我们提供了闭包机制(Java7 和 Go 也是这种思路),本文简单的做个解释。背景知识你必须了解:引用类型、值类型、引用、对象、值类型的值(简称值)。关于引用、对象和值在内存的分配有如下几点规则:对象分配在堆中。作为字段的引用分配在堆中(内嵌在对象中)。作为局部变量(参数也是局部变量)的引用分配在栈中。作为字段的值分配在堆中(内嵌在对象中)。作为局部变量(参数也是局部变量)的值用分配在栈中。局部变量只能存活于所在的作用域(方法中的大括号确定了作用域的长短)。注:按值传递和按引用传递也是需要掌握的知识点,C# 默认是按值传递的。闭包示例测试代码 1 pri... 阅读全文

posted @ 2013-11-13 17:03 幸福框架 阅读(6794) 评论(10) 推荐(7) 编辑

.NET:CLR via C# Compute-Bound Asynchronous Operations
摘要:线程槽使用线程池了以后就不要使用线程槽了,当线程池执行完调度任务后,线程槽的数据还在。测试代码 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading; 6 using System.Threading.Tasks; 7 using System.Runtime.Remoting; 8 9 namespace ExecutionContextStudy10 {11 class Program12 ... 阅读全文

posted @ 2013-11-11 23:33 幸福框架 阅读(896) 评论(0) 推荐(0) 编辑

.NET:CLR via C#:Runtime Serialization
摘要:Making a Type SerializableThe SerializableAttribute custom attribute may be applied to reference types (class), value types (struct), enumerated types (enum), and delegate types (delegate) only. (Note that enumerated and delegate types are always serializable, so there is no need to explicitly apply 阅读全文

posted @ 2013-11-10 10:09 幸福框架 阅读(1854) 评论(0) 推荐(0) 编辑

.NET:CLR via C# Thread Basics
摘要:A thread is a Windows concept whose job is to virtualize the CPU.Thread OverheadThread kernel objectThe operating system allocates and initializes one of these data structures for each thread created in the system. The data structure contains a bunch of properties that describe the thread. This data 阅读全文

posted @ 2013-11-09 16:03 幸福框架 阅读(570) 评论(0) 推荐(0) 编辑

.NET:CLR via C#:CLR Hosting And AppDomains
摘要:AppDomain UnloadingTo unload an AppDomain, you call AppDomain’s Unload static method.This call causes the CLR to perform a lot of actions to gracefully unload the specified AppDomain:The CLR suspends all threads in the process that have ever executed managed code.The CLR examines all of the threads’ 阅读全文

posted @ 2013-11-08 10:41 幸福框架 阅读(873) 评论(0) 推荐(0) 编辑

.NET:何时应该 “包装异常”?
摘要:背景提到异常,我们会想到:抛出异常、异常恢复、资源清理、吞掉异常、重新抛出异常、替换异常、包装异常。本文想谈谈 “包装异常”,主要针对这个问题:何时应该 “包装异常”?“包装异常” 的技术形式包装异常是替换异常的特殊形式,具体的技术形式如下:1 try2 {3 // do something4 }5 catch (SomeException ex)6 {7 throw new WrapperException("... 阅读全文

posted @ 2013-11-05 08:59 幸福框架 阅读(1857) 评论(4) 推荐(1) 编辑

.NET:如何实现 “热插拔”?
摘要:背景如果某个“功能”需要动态更新?这种动态更新,可能是需求驱动的,也可能是为了修改 BUG,面对这种场景,如何实现“热插拔”呢?先解释一下“热插拔”:在系统运行过程动态替换某些功能,不用重启系统进程。几种方案脚本化:采用 Iron 或 集成其它脚本引擎。AppDomain:微软的 Add In 框架就是为这个目的设计的。分布式 + 负载平衡 :轮流更新集群中的服务器。Assembly.LoadFrom + 强签名程序集:因为相同标识的程序集在内存中只会加载一次,所以每次功能发生变化,都要增加程序集的版本号。Assembly.Load + + 强签名程序集 + GAC:因为相同标识的程序集在内存 阅读全文

posted @ 2013-11-04 08:59 幸福框架 阅读(10332) 评论(13) 推荐(3) 编辑

.NET:CLR via C# Shared Assemblies and Strongly Named Assemblies
摘要:Two Kinds of Assemblies, Two Kinds of DeploymentA strongly named assembly consists of four attributes that uniquely identify the assembly: a file name (without an extension), a version number, a culture identity, and a public key. Because public keys are very large numbers, we frequently use a small 阅读全文

posted @ 2013-11-03 10:28 幸福框架 阅读(1073) 评论(0) 推荐(0) 编辑

.NET:CLR via C# Manifest
摘要:An assembly is a collection of one or more files containing type definitions and resource files. One of the assembly’s files is chosen to hold a manifest. The manifest is another set of metadata tables that basically contain the names of the files that are part of the assembly. They also describe th 阅读全文

posted @ 2013-11-02 08:47 幸福框架 阅读(717) 评论(0) 推荐(0) 编辑

.NET:鲜为人知的 “Load Context”
摘要:背景任何一门语言都要了解其类型加载过程,如:Java 的 Class Loader,NodeJS 的搜索方式等,本文概述一下我对 CLR 如何加载程序集,重点说一下 Load Context。其编译时只是在程序集中生成了元数据(如:依赖的程序集标识)和代码。当代码执行时,CLR 会根据元数据加载依赖的程序集。Load Context参考文章:http://msdn.microsoft.com/en-us/library/dd153782(v=vs.110).aspx。Assembly 会被加载到三个 Load Context 中的任意一个,或者没有在任何上下文中,这三个 Load Contex 阅读全文

posted @ 2013-10-31 22:20 幸福框架 阅读(3125) 评论(2) 推荐(4) 编辑

.NET:CLR via C# A Brief Look at Metadata
摘要:基础知识A managed PE file has four main parts: the PE32(+) header, the CLR header, the metadata, and the IL. The PE32(+) header is the standard information that Windows expects. The CLR header is a small block of information that is specific to modules that require the CLR (managed modules). The header 阅读全文

posted @ 2013-10-30 18:03 幸福框架 阅读(760) 评论(0) 推荐(0) 编辑

.NET:CLR via C# The CLR’s Execution Model
摘要:The CLR’s Execution ModelThe core features of the CLRmemory management.assembly loading.security.exception handling.thread synchronization.Managed ModuleParts of a Managed Module:PE32 or PE32+ header:The standard Windows PE file header, which is similar to the Common Object File Format (COFF) header 阅读全文

posted @ 2013-10-29 12:17 幸福框架 阅读(847) 评论(2) 推荐(1) 编辑

.NET:命令行解析器介绍
摘要:背景经常需要开发一下小工具,之前都是自己解析命令行参数,接触过动态语言社区以后,发现命令行解析有特定的模式和框架可以利用,本文介绍一个 .NET 平台的类库。示例需求拷贝文件,如:CopyFiles -s "E:\Framework\Tenoner - 副本 (2)" -p "*.csproj" -t "E:\Framework\Tenoner - 副本 (2)\Bak",可以支持:深度拷贝、拷贝符合指定模式的文件、是否覆盖等选秀。使用CommandLineParserCommandLineParser是一个轻量级的工具,使用非常简答 阅读全文

posted @ 2013-10-23 09:03 幸福框架 阅读(2335) 评论(8) 推荐(2) 编辑

.NET:异常处理的两条“黄金定律”,求批!
摘要:背景架构之处必须考虑:如何处理异常?如何定义自己的异常体系?本文为了强化这个概念而写。异常处理的两条“黄金定律”自己抄袭的两条规律:异常不能穿过“边界类”。异常不能在没有恢复的情况下“吞掉”。我们会将异常分为两类:“需要恢复”和“不需要恢复”,“需要恢复”的异常如果到达了边界类,就说明系统有BUG了,这类异常需要记录到日志。“不需要恢复”的异常需要进一步分为:“我们不能恢复”和“我们不期望恢复”,如果这类异常到达边界类,“我们不能恢复“的异常同样需要记录到日志,“我们不期望恢复”的异常则直接将异常信息显示给界面。一般采用AOP处理边界异常。示例AOP 1 using System; 2 usi 阅读全文

posted @ 2013-10-21 23:50 幸福框架 阅读(2646) 评论(7) 推荐(4) 编辑

.NET:C#的匿名委托 和 Java的匿名局部内部类
摘要:背景这几天重温Java,发现Java在嵌套类型这里提供的特性比较多,结合自身对C#中匿名委托的理解,我大胆的做了一个假设:Java的字节码只支持静态嵌套类,内部类、局部内部类和匿名局部内部类都是编译器提供的语法糖,这个假设目前没法验证(看不懂字节码),本文先来看一下C#是如何为我们提供的这种语法糖。实验测试代码 1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace CS. 阅读全文

posted @ 2013-09-24 13:12 幸福框架 阅读(4005) 评论(0) 推荐(1) 编辑

.NET:动态代理的 “5 + 1” 模式
摘要:背景什么叫“动态代理”,代理模式我们都知道,动态代理就是动态生成的代理(采用Emit)。重量级的ORM和IOC产品离不开动态代理,作为开发人员,多数情况不用关注动态代理的内部实现机制,但是了解其一般的规律和模式还是有必要的,比如:虽然你开发期间采用了POCO,因为开启了动态代理,运行期间则不是POCO。本文简单描述了5种代理生成模式和1种Mixin模式,最后给出一个示例。公共代码这里先给出公共代码。 1 public interface IPlayable 2 { 3 void Play(); 4 } 5 6 public class Anim... 阅读全文

posted @ 2013-09-02 08:59 幸福框架 阅读(8357) 评论(6) 推荐(5) 编辑

.NET:脏读、不可重复读和幻读测试
摘要:背景昨天才发现如果一条数据被A事务修改但是未提交,B事务如果采用“读已提交”或更严格的隔离级别读取改数据,会导致锁等待,考虑到数据库默认的隔离级别是“读已提交”,在嵌套事务 + 子事务中有复杂的SQL查询,很可能会出现死锁,后面会给出嵌套事务导致死锁的示例。先来看看:脏读、不可重复读和幻读。脏读原因当B事务在A事务修改和提交之间读取被A事务修改的数据时,且B事务,采用了“读未提交”隔离级别。重现和避免测试代码 1 public static void 脏读测试() 2 { 3 Console.WriteLine("\n**********... 阅读全文

posted @ 2013-08-27 09:23 幸福框架 阅读(4832) 评论(3) 推荐(3) 编辑

导航

我要啦免费统计