In an application a user can create an order. When the order is created it is on pending for payment status. Since a pending order locks the product, a user can only have one order in pending for payment. This order can either be paid or be cancelled (in a limited time). The method that creates the order checks this in the DB and if there is no other pending order, it creates a bunch of rows and then redirects to payment gateway. This could produce a race condition, so two threads check the DB at the same time and they both create the order. I wanted to know can I decorate my CreateOrder
method with the [MethodImplAttribute(MethodImplOptions.Synchronized)]
attribute to solve the problem? Is this OK? Are there any issues that I'm not aware of?
There is no code yet, I'm in the design process and I'm evaluating my options. I read this and it is very complex. I also read this which seems very simple. Could you please tell me why the answer is no? I got suspicious that life can't be that easy and there is probably a gotcha somewhere. :D