RSS 2.0 Feed
2005-04 Entries
摘要: 把VS.NET2005Beta2下载了下来,一直都没有好好地去研究一下。今天突然想到一个有意思的Idea,关于程序中数据的获取方式的。反正想试试而已,于是顺便练习了一下范型。通常做数据缓存的时候,都是依靠Cache来实现的。其实DotNet的垃圾回收和WeakReference类就可以用来做缓存了。测试的代码如下://5 using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Data; using System.Data.SqlClient; namespace Test1 { #region 第一部分,通用的 public interface IDataItemProvider<K, T> { void GetItem(SomeContext context, K key, out T val); } public class SomeContext { public SomeContext(SqlConnection conn) { if (conn == null) throw (new ArgumentNullException("conn")); ......[阅读全文]

posted @ | Feedback (8) | Filed Under [ 迷失中 DotNet DotNet2学习 ]

摘要:DateTime.Now的精度是很低,这个低的意思是,两次获取的DateTime.Now的Ticks的差,只是一个较大数的整数倍。例如在我的机器上,这个差最小是10.114ms。所以,如果我用DateTime.Now来计算时间差,那么就无法精确到10ms以内。 后来发现ASP.NET的TRACE的精度很高,用Reflector看它的实现,发现了它是使用这两个方法的: 参考MSDN:How To: Time Managed Code Using QueryPerformanceCounter and QueryPerformanceFrequency 我自己了按照这个写了个类,代码如下using System; using System.Runtime.InteropServices; public class A { [DllImport("kernel32.dll")] static extern bool QueryPerformanceCounter([In, Out] ref long lpPerformanceCount); [DllImport("kernel32.dll")] static extern bool QueryPerformanceFrequency([In, Out] ref long lpFrequency); static long _f = 0; static public long GetTickCount() { long f = _f; if (f == 0) { ......[阅读全文]

posted @ | Feedback (18) | Filed Under [ DotNet AspNet ]