Hi,
We know that TransactionScope class can use user-defined timeout value. But timeout exception is thrown while exiting from the using {} block. How to throw this timeoutexception immediately after elapsed timeout value?
Hi,
We know that TransactionScope class can use user-defined timeout value. But timeout exception is thrown while exiting from the using {} block. How to throw this timeoutexception immediately after elapsed timeout value?
This is not possible.
The TransactionScope simply stores the time that you started the transaction, then checks that time when committing the transaction.
It has no way to throw an exception at any arbitrary point.
In general, the only exception that can be thrown at any point in execution (of managed code) is ThreadAbortException
.
Therefore, if you really wanted to, you could make a separate thread that sleeps for the duration of the timeout, then aborts your original thread.
However, that's a horrible idea.