代码改变世界

随笔分类 -  .Net

.NET面试题

2009-11-06 23:06 by 敏捷的水, 75 阅读, 收藏, 编辑
该文被密码保护。 阅读全文

.NET多线程小记(6):线程同步

2009-11-06 15:15 by 敏捷的水, 560 阅读, 收藏, 编辑
摘要: 同步块的机制: 在.NET被加载时初始化同步块数组 每一个被分配在堆上的对象都会包含两个额外的字段,其中一个存储类型指针,而另外一个就是同步块索引,初始时被赋值为-1. 当一个线程试图使用该对象进入同步时,会检查该对象的同步索引。如果索引为负数,则会在同步块数组中寻找或者新建一个同步块,并且把同步块的索引值写入该对象的同步索引中。如果该对象的同步索引不为负值,则找到该对象的同步块并且检查是否有其他... 阅读全文

.NET多线程小记(7):进程同步Mutex

2009-11-06 15:15 by 敏捷的水, 967 阅读, 收藏, 编辑
摘要: 互斥体是跨进程的同步,效率非常低 using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;using System.Threading;using System.Diagnostics;namespace MultiThreadTest{ class Pro... 阅读全文

.NET多线程小记(5):线程独享数据TLS

2009-11-06 15:13 by 敏捷的水, 803 阅读, 收藏, 编辑
摘要: 线程本地存储(Thread Local Storage TLS) 在.NET程序中,静态变量是全局(整个应用程序域)可见的数据,一个普通的静态变量对于应用程序域内的所有线程都是可见并且是可访问的。 TLS是指存储在线程环境块内的一个结构,用来存放该线程内独享的数据。进程内的线程不能访问不属于自己的TLS,这就保证了TLS内的数据在线程内是全局共享的,而对于线程外却是不可见的。   ... 阅读全文

.NET多线程小记(4):线程池

2009-11-06 15:01 by 敏捷的水, 571 阅读, 收藏, 编辑
摘要: .NET线程池 线程池中运行的线程都为后台线程,线程的IsBackground属性都会被设为true.所谓的后台线程是指这些线程的运行不会阻碍应用程序的结束。相反的,应用程序必须等待所有前台线程结束后才能退出。 示例 using System;using System.Collections.Generic;using System.Linq;using System.Text;using ... 阅读全文

.NET多线程小记(3):线程的状态

2009-11-06 14:57 by 敏捷的水, 578 阅读, 收藏, 编辑
摘要: 线程的状态 using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace MultiThreadTest{ class Program { static void Main(string[] args) { Console.Wri... 阅读全文

.NET多线程小记(2):多线程示例

2009-11-06 14:53 by 敏捷的水, 454 阅读, 收藏, 编辑
摘要: 多线程示例: using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;namespace MultiThreadTest{ class Program { static void Main(string[] args) { Console.Wri... 阅读全文

.NET多线程小记(1):进程、线程、纤程

2009-11-06 14:48 by 敏捷的水, 1751 阅读, 收藏, 编辑
摘要: 进程 进程代表了操作系统上运行着的一个应用程序。进程拥有自己的程序块,拥有独占的资源和数据,并且可被操作系统来调度。即使同一个应用程序,当被强制多次启动时,也会被安装到不通的进程之中单独运行。 线程 线程有时候也被称为微进程或者轻量级进程,它的概念和进程十分相似,是一个可以调度的单元,并且维护自己的堆栈和上下文环境。线程是附属于进程的,一个进程可以包含一个或者多个线程,并且同一个进程内的多个线... 阅读全文

[Tips]:值类型和引用类型的一个例子

2009-07-22 15:56 by 敏捷的水, 428 阅读, 收藏, 编辑
摘要: using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { string[] a = { "a", "b", "c", "d" }; ... 阅读全文

[tips]: 多线程 ManualResetEvent

2009-05-21 14:23 by 敏捷的水, 512 阅读, 收藏, 编辑
摘要: WaitHandle用于实现对共享资源的独占访问,AutoResetEvent和ManualResetEvent都继承自它。 WaitHandle.WaitOne方法将阻塞当前线程,直到WaitHandle收到信号。但有时候,我们需要非阻塞的方式测试WaitHandle 状态。 public virtual bool WaitOne(int millisecondsTimeout)可以指定等待的... 阅读全文

[Tips]:Read value from Resource file in C#

2009-05-18 16:18 by 敏捷的水, 1016 阅读, 收藏, 编辑
摘要: 1: //Namespace reference 2: using System; 3: using System.Resources; 4:  5:  6: #region ReadResourceFile 7: /// <summary> 8: /// method for reading a value from a resource file 9: /// ... 阅读全文

Get countries from system

2009-05-08 16:02 by 敏捷的水, 34 阅读, 收藏, 编辑
该文被密码保护。 阅读全文

代码段:ASCII to Unicode

2009-04-17 10:44 by 敏捷的水, 714 阅读, 收藏, 编辑
摘要: 1: private string ConvertAsciiToUnicode(string theAsciiString) 2: { 3: // Create two different encodings. 4: Encoding aAsciiEncoding = Encoding.ASCII; 5: Encoding aUnicodeEncoding = Encoding.Unicode;... 阅读全文

MSIL(1): Hello World

2009-03-09 22:14 by 敏捷的水, 671 阅读, 收藏, 编辑
摘要: 1. 用记事本编写如下代码.assembly HelloWorld{}.assembly extern mscorlib{}.class HelloWorld extends [mscorlib]System.Object{ .method public static void HelloWorld() { .maxstack 1 ldstr "Hello World" call void [... 阅读全文

MSIL(0):简介

2009-03-04 23:06 by 敏捷的水, 861 阅读, 收藏, 编辑
摘要: Microsoft Intermediate Language (MSIL)微软中间语言 MSIL是将.NET代码转化为机器语言的一个中间过程。它是一种介于高级语言和基于Intel的汇编语言的伪汇编语言。当用户编译一个.NET程序时,编译器将源代码翻译成一组可以有效地转换为本机代码且独立于CPU的指令。当执行这些指令时,实时(JIT)编译器将它们转化为CPU特定的代码。由于公共语言运行库支持多种... 阅读全文

C#拾遗系列(9):继承、接口、扩展方法、分部类、类操作、Ref and Out、可空类型

2008-06-19 15:07 by 敏捷的水, 1351 阅读, 收藏, 编辑
摘要: 本文内容: 继承 Equal示例 结构和类 属性 Ref and Out 类操作 扩展方法 接口 可空类型 分部类 1. 继承 using System; using System.Collections.Generic; using System.Linq; using System.Text; names... 阅读全文

C#拾遗系列(8):异常

2008-06-19 11:02 by 敏捷的水, 387 阅读, 收藏, 编辑
摘要: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace NetTest { public class TestException { public void TestThrow() { ... 阅读全文

C#拾遗系列(7):自定义属性

2008-06-18 14:52 by 敏捷的水, 1532 阅读, 收藏, 编辑
摘要: 1 .描述 属性提供功能强大的方法以将声明信息与 C# 代码(类型、方法、属性等)相关联。属性与程序实体关联后,即可在运行时使用名为“反射”的技术查询属性。 属性以两种形式出现: 一种是在公共语言运行库 (CLR) 中定义的属性。 另一种是可以创建的用于向代码中添加附加信息的自定义属性。此信息可在以后以编程方式检索。 2. 示例代码: using System; using S... 阅读全文

C#拾遗系列(6):迭代器

2008-06-14 23:03 by 敏捷的水, 389 阅读, 收藏, 编辑
摘要: 1. 示例: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Collections; namespace NetTest { public class TestIteration { public void ... 阅读全文

C#拾遗系列(5):泛型委托

2008-06-14 17:25 by 敏捷的水, 444 阅读, 收藏, 编辑
摘要: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace NetTest { //泛型委托 class TestGenericDelegate { public delegate void StackEventHa... 阅读全文