I have a C# application that generates a Sequential GUID for each row that I insert into a table. I expect the inserted GUIDs to be sequential, but sometimes they break sequence (in chunks).
Example:
These GUIDs are shown in the order that they are inserted.
Why are these 'sequential' GUIDs being created with such a large break of sequence?
Code used to generate sequential GUIDs:
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.
}
Code used in a loop to insert new GUIDs and information into table:
Guid mySequentialGUID = CreateSequentialGuid();
string[] row = { item1,
item2,
item3,
sourceText,
encoding.ToString(),
mySequentialGUID.ToString()
};
var listViewItem = new ListViewItem(row);
myListView.Items.Add(listViewItem);
Edit: Please see this question to understand Sequential GUIDs: