I am new to Azure. I would like to create a function that returns the sequence number. I have created a function using Thread mutex to lock the sequence number. I tested the below code with around 10k parallel requests. The problem is I am getting duplicates sequence number when doing the testing, mutex is not working. I am not sure what to do to avoid duplication instead generate running number for each request
Public class MySharedMutexCounter {
public static long count = 0;
public static Mutex ObjMutex = new Mutex(false,"SeqGenerator");
}
public long GetSequnceNo(){
long seqId = -1;
try{
MySharedMutexCounter.ObjMutex.waitOne();
seqId = ++MySharedMutexCounter.count;
if(seqId > 100){
MySharedMutexCounter.count = 0;
seqId = ++MySharedMutexCounter.count;
}
return seqId;
}finally{
MySharedMutexCounter.ObjMutex.RelaseMutex();
}
return -1;
}