I would like to set a configurable timeout value for my AsyncController I know that we have [asyncTimeout (5000) )]
to decorate a method with attribute and we are able to use value with a const variable. I would like to use a fixed variable so that I can do a more configurable way to set the deadline after compiling.
Reading it seems like there is a property that can be called a timeout.
Here's what I have tried, that is.
[http pps] Public Zero DwarfsSync (Miley Query) {AsyncManager.Timeout = TestTimeout; // Testimet 120000 is a static entity for the async manager. Breakthrough Operation Incorporation (); (Do work) ...}
It seems that the AsyncManager.Timeout value is not being used and instead of throwing the timeout expression after the default 45 seconds.
Is there a way to set the value of this timeout when compiling time?
You AsyncTimeoutAttribute
this way
Public class CustomAsyncTimeoutAttribute: AsyncTimeoutAttribute {Public CustomAsyncTimeoutAttribute (): Base (Params.TimeOut) {}}
Where Parameters. There is a static timeout variable in the timeout
.
Or you can try it (just copy / paste base In addition, you should mark your action method with For example: asyncTimeout functionality):
public class CustomAsyncTimeoutAttribute: AsyncTimeoutAttribute {public CustomAsyncTimeoutAttribute ( ): Base (0) {} Public Override Zero OnActionExecuting (ActionExecutingContext FilterContext) {if (filterContext == null) Throw new logic NullException ("filterContext"); Var managerContainer = filterContext.Controller IAsyncManagerContainer; If (managerContainer == zero) new invalid operation throw exception ("Operation timed out."); ManagerContainer.AsyncManager.Timeout = // You can get your timeout parameter from the resource (i.e. config file, database, etc.); Base.OnActionExecuting (filterContext); }}
async
keywork, your method should be work
or Work & lt; T & gt;
, and your method should have the last parameter cancellation token
, otherwise AsyncTimeout
will not work.
< / Div> [customAsyncTimeoutAttribute] public async job execution function (/ * some parameters /, canceled token token)
No comments:
Post a Comment