G
Guest
Hi all,
I cannot seem to solve this problem: I am attempting to generate a
unique filename with the help of the Random Number Generator
(RND.Next.ToString). All seems to work fine except that one third of the
time, I get duplicate file names; this poses a critical problem for my
application. The problem only seems to happen when Method1 calls Function2
to generate and return the random file name. If I move the logic to generate
the filename into Method1, it works properly. I have tried to use SyncLock,
etc. but to no avail.
Why is it that when Method1 calls Function2 to generate the random file
name, I get duplicates, whereas if I move the logic from Function2 into
Method1, I get no duplicate file names. Is this due to threading? I am lost
as to how to solve this seemingly simple problem.
Note: I have also tried the above replacing the Random Number
Generator with the Now.Second and Now.MilliSecond but with the exact same
results. It only works if it is done within the same method that is doing my
actual processing.
Regards,
Giovanni
I cannot seem to solve this problem: I am attempting to generate a
unique filename with the help of the Random Number Generator
(RND.Next.ToString). All seems to work fine except that one third of the
time, I get duplicate file names; this poses a critical problem for my
application. The problem only seems to happen when Method1 calls Function2
to generate and return the random file name. If I move the logic to generate
the filename into Method1, it works properly. I have tried to use SyncLock,
etc. but to no avail.
Why is it that when Method1 calls Function2 to generate the random file
name, I get duplicates, whereas if I move the logic from Function2 into
Method1, I get no duplicate file names. Is this due to threading? I am lost
as to how to solve this seemingly simple problem.
Note: I have also tried the above replacing the Random Number
Generator with the Now.Second and Now.MilliSecond but with the exact same
results. It only works if it is done within the same method that is doing my
actual processing.
Regards,
Giovanni