TransactionScope and Timeout Issue

不打扰是莪最后的温柔 提交于 2019-12-24 17:18:04

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3344082/transactionscope-and-timeout-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!