Is there a way to generate every time a 100% new GUID without any chance to collide within entire application?
Since I cannot answer my question in eight hours, I come up with the solution:
internal static class GuidGenerator
{
private static readonly HashSet<Guid> _guids = new HashSet<Guid>();
internal static Guid GetOne()
{
Guid result;
lock (_guids)
while (!_guids.Add(result = Guid.NewGuid())) ;
return result;
}
internal static void Utilize(Guid guid)
{
lock (_guids)
_guids.Remove(guid);
}
}
Is this code solves the problem within the app?
EDIT: Uh, its getting complicated. Thread safety kills the speed.