2011年4月1日

摘要: 上篇中使用了ThreadPool加上Socket同步方式实现多客户端和单服务器端通讯,稍加修改,得到异步编程模型实现方式主要使用到Socket的BeginSend, EndSend, BeginAccept, EndAccept, BeginReceive, EndReceive代码:// Server端namespaceSocketAPMServer{publicpartialclassForm1:Form{Socketsocket;publicForm1(){InitializeComponent();InitSocket();}privatevoidInitSocket(){socket 阅读全文
posted @ 2011-04-01 14:45 o0myself0o 阅读(1550) 评论(1) 推荐(0) 编辑
摘要: 代码如下:namespaceProduceConsume{classProgram{staticvoidMain(string[]args){intresult=0;Productproduct=newProduct();Producerproducer=newProducer{Product=product,Looper=10};Consumerconsumer=newConsumer{Product=product,Looper=10};ThreadthreadP=newThread(newThreadStart(producer.Process));Thread.Sleep(500);T 阅读全文
posted @ 2011-04-01 12:15 o0myself0o 阅读(555) 评论(1) 推荐(1) 编辑

2011年3月31日

摘要: 线程池:线程池使用方式:ThreadPool.QueueUserWorkItem(WaitCallback callBack, object state)WaitCallback的方法签名:public delegate void WaitCallback(object state) ; //传入一个object上下文Socket:常用实例方法:Connect(), Bind(EndPoint localEP), Listen(int backlog), Accept(), Receive(byte[] buffer), Close()示例:// Server端namespaceSocketM 阅读全文
posted @ 2011-03-31 10:14 o0myself0o 阅读(2647) 评论(2) 推荐(0) 编辑

2011年2月26日

摘要: 1. AddObject View Code 1 privatestaticvoidAddObjectDemo1()2{3Console.WriteLine("--------BeginAddObjectDemo1");4using(varedm=newNorthwindEntities())5{6CustomersaddCustomer=edm.Customers.FirstOrDefault(c=>c.CustomerID=="001");7if(addCustomer==null)8{9Customerscustomer=newCustome 阅读全文
posted @ 2011-02-26 15:22 o0myself0o 阅读(614) 评论(0) 推荐(0) 编辑

2011年2月25日

摘要: 上次在跟一个朋友吃饭的时候,他说起他那个时候的一个面试题,闲来无事,顺手做了下。 题目是:若干个不重复数,打乱顺序输出,用javascript实现 实现如下: window.onload=function(){//1到100,打乱顺序输出outputOne();document.write("<br/><br/>");//自定义的列表,打乱顺序输出outputTwo();};functionoutputOne(){varcount=100;varsize=10;for(vari=1;i<=count;i++){document.write(i+ 阅读全文
posted @ 2011-02-25 14:27 o0myself0o 阅读(487) 评论(3) 推荐(0) 编辑

2010年7月23日

摘要: 大家都知道,Javascript是面向对象的,所以在字符串或数字常量上使用方法是可以的。比如"hello world".toUpperCase();// HELLO WORLD3.toString()// 报错......3..toString()// 3 --不报错,对,你没有看错,3后面两个点,WTF? 哦,原来在数字常量在调用方法的时候,需要这个数字后面带有.,也就是要是浮点数,3.在Jav... 阅读全文
posted @ 2010-07-23 09:04 o0myself0o 阅读(169) 评论(0) 推荐(0) 编辑

2010年7月21日

摘要: 在javascript中你如何确定一个Number类型的数据是整型? x = 1;x === Math.floor(x);//return true如果要把这个写成Number的一个扩展方法呢?你会说,很简单啊,看下面:Number.prototype.isInteger = function(){  return this === Math.floor(this); }x = 1;x.isInt... 阅读全文
posted @ 2010-07-21 12:32 o0myself0o 阅读(327) 评论(0) 推荐(0) 编辑

2010年7月12日

摘要: 大家觉得这个结果是多少:console.log((!+[]+[]+![]).length); // 9what's the fuck? console.log((!+[]+[]+![]));// truefalse哈哈,it's funny, isn't it? 阅读全文
posted @ 2010-07-12 08:59 o0myself0o 阅读(158) 评论(0) 推荐(0) 编辑

2010年7月7日

摘要: namespace Sort{ class Program { static void Main(string[] args) { /* * 给定两个已从小到大排好序的整型数组arrA和arrB * 将两个数组合并成arrC,使得arrC也要按从小到大的顺序排好序 */ int[] arrA = new int[] { 1, 3, 5, 9, 10 }; int[] arrB = new int[... 阅读全文
posted @ 2010-07-07 11:21 o0myself0o 阅读(1007) 评论(3) 推荐(0) 编辑

2010年6月26日

摘要: public class SingletonProvider<T> where T : new() { SingletonProvider() { } public static T Instance { get { return SingletonCreator.instance; } } class SingletonCreator { static SingletonCreato... 阅读全文
posted @ 2010-06-26 17:27 o0myself0o 阅读(244) 评论(0) 推荐(0) 编辑

导航