- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个 C# 应用程序,它为我插入到表中的每一行生成一个顺序 GUID。我希望插入的 GUID 是连续的,但有时它们会破坏序列(成 block )。
例子:
这些 GUID 按插入顺序显示。
为什么创建这些“顺序”GUID 时会出现如此大的序列中断?
用于生成顺序 GUID 的代码:
class NativeMethods
{
[DllImport("rpcrt4.dll", SetLastError = true)]
public static extern int UuidCreateSequential(out Guid guid);
}
public static Guid CreateSequentialGuid()
{
const int RPC_S_OK = 0;
Guid guid;
int result = NativeMethods.UuidCreateSequential(out guid);
if (result == RPC_S_OK)
return guid;
else
return Guid.NewGuid(); //<--In debugging, this statement never runs.
}
循环中用于将新 GUID 和信息插入表中的代码:
Guid mySequentialGUID = CreateSequentialGuid();
string[] row = { item1,
item2,
item3,
sourceText,
encoding.ToString(),
mySequentialGUID.ToString()
};
var listViewItem = new ListViewItem(row);
myListView.Items.Add(listViewItem);
编辑:请查看此问题以了解顺序 GUID:
最佳答案
我认为问题在于您假设“顺序”意味着“递增”。尽管您的示例表明有时会发生这种情况,但文档中并不能实际保证会发生这种情况。我们可能会争论“序列”的定义,或者这个函数的命名可能很糟糕甚至是错误的,但归根结底,根据文档,它似乎 100% 完全按照定义工作:
Creates a GUID that is greater than any GUID previously generated by this function
对于对“顺序 GUID”的一般概念有疑问的人,请使用关于“遵循逻辑顺序”的“序列”定义,并尝试记住 Melissa 病毒。这是 mildly document by this line :
For security reasons, UuidCreate was modified so that it no longer uses a machine's MAC address to generate UUIDs. UuidCreateSequential was introduced to allow creation of UUIDs using the MAC address of a machine's Ethernet card.
所以“序列”是基于 MAC 地址的 GUID。
回到 OP 的问题,对于为什么您的 GUID 每次都不会递增 1,我的最佳猜测是一个简单的事实,即您可能不是唯一调用此函数的人。这是 Windows 的核心功能,必然会有其他组件、程序、服务等使用它。
关于c# - 生成的顺序 GUID 有时不是顺序的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41899426/
我有某些场景(例如,一个自定义类来保存 Sql 参数),其中可能需要也可能不需要变量。传统上,我一直将这些定义为 Guid? 类型,并在使用前使用 myGuid.HasValue 检查有效值。 当然在
在 rpc.h 中,GUID 结构声明如下: typedef struct _GUID { DWORD Data1; WORD Data2; WORD Data3; B
使用 Dynamics CRM 我试图创建一个实体的实例。我想手动设置 GUID,但如果我拥有作为 DynamicEntity 主键的属性,则会出现以下错误。 Service could not pr
我需要将 GUID PK 字段(长度 = 36)发送到只接受 20 个字符长的下游系统。在下游系统中增加字段的长度成本过高。如果我截断该字段,那么我将失去它的唯一性。 有什么方法可以在不丢失唯一性的情
我听说 melissa 蠕虫的创建者因生成的 GUID 可以链接回他使用的计算机的 MAC 地址而被定罪。 做到这一点有多难?除了 GUID,他们还需要哪些数据?喜欢 MAC 地址本身还是创建时间?
使用 GUID 作为文件名和 นด 上传的图像以避免重复有什么缺点吗? 最佳答案 您的文件名将是唯一的,真的。但是没有任何方法可以按任何顺序对它们进行排序。 您可以使用 Unix TimeStamp在
我正在做一些互操作,需要传递一些 GUID。有没有办法将 GUID 属性添加到枚举值,并且当它被编码时它具有适当的值? 基本上我正在尝试转换代码 #if !defined( STATIC_KSDATA
我有一个文件,其中包含大量出现的字符串 Guid="GUID HERE" (其中 GUID HERE 在每次出现时都是唯一的 GUID),我想用新的唯一 GUID 替换每个现有的 GUID。 这是在
我已经向我们的客户发送了 10000 封邮件,每封邮件都有一个格式的链接 http://example.com/LogIn?key={guid} 不幸的是guid我发送的是随机 guids(由 Gui
使用 Breeze,在创建实体时填充 GUID 键的最简单方法是什么? 最佳答案 我假设您的实体已配置为客户端负责为新实体设置 Guid 键。这是 Entity Framework 代码优先实体的 G
我看到这两个首字母缩略词被抛出,我想知道 GUID 和 UUID 之间是否有任何区别? 最佳答案 简单回答是:**没有区别,它们是同一个东西。 2020-08-20 更新 :虽然 GUID(由 Mic
我注意到有些人不打算使用通常的递增数字作为 ID,而是简单地生成 GUID。优点包括: 快速简单 无需跟踪以前的 ID 即使在机器之间互不了解的情况下也能保证唯一性 一些缺点是: 可能存在性能瓶颈 使
我是 C++/CLI 的新手,我正在尝试将 native C++ GUID 转换为我的 C++/CLI Guid^。尝试转换时: BlockInfo^ blockInfo = gcnew BlockI
这个问题在这里已经有了答案: 11 年前关闭。 Possible Duplicate: Is there any difference between a GUID and a UUID? GUID
我正在使用 Data::GUID生成 GUID。然而,每当我在同一个“ session ”中生成 GUID,即运行脚本时,唯一改变的数字是最前面的数字: 3BAF1240-0573-11E4-B31C
我有一个对象列表,它们具有 id 的 guid。我想使用这个对象列表中的 id 创建一个 guid,我可以使用它来确保列表没有改变。如果删除/添加了一个对象,则 guid 会有所不同。我想到的是使用哈
上下文:ASP.NET Web API v2 给定一个类似于这个的 URL: http://localhost/something?id=cbc66d32-ece8-400f-a574-e36b911
这是将 Guid 转换为 Guid 的惯用方法吗?? new Guid?(new Guid(myString)); 最佳答案 不,这是: Guid? foo = new Guid(myString);
我想从输入字符串生成一个 GUID。假设我从用户那里收到了 guid,它是 81a130d2-502f-4cf1-a376-63edeb000e9f 所以我可以这样做: Guid g = Guid.
为什么无参数 Guid 构造函数生成一个空 GUID,而不是像 Guid.NewGuid() 那样默认生成一个? 空 Guid 是否有特殊用途? 最佳答案 Why does the parameter
我是一名优秀的程序员,十分优秀!