/// <summary>
///
/// </summary>
public static class DataBaseGenerator
{
/// <summary>
///
/// </summary>
private static Int64 seed = Int64.Parse(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds.ToString("0"));
/// <summary>
///
/// </summary>
/// <returns></returns>
public static Int64 GetPrimaryKey()
{
return Interlocked.Increment(ref seed);
}
}
这个不错,把我的也供献一下
private static object IdLock = new object();
/// <summary>
/// 返回16位时间戳字符
/// </summary>
public static string GetNewId()
{
string newid = "";
lock (IdLock)
{
Thread.Sleep(1);
newid = System.DateTime.Now.ToString("yyMMddHHmmssffff");
}
在win2003中,Thread.Sleep(15),系统问题,没办法到1
return newid;
}
http://www.cnblogs.com/jiang_zheng/archive/2011/10/09/2203534.html#commentform