c# - Calling Asynchronous method after certain time has passed -
I have the following code in .Net C #, which calls, and then evaluates the response. If the response is pending, I want to wait 2 seconds, and I want to call again.
I do not know how to "wait 2 seconds", or how to use the timer working with synchronous method.
I am limited by the constraints of any PCL project.
Private async Tasks & lt; Feedback & gt; ExecuteTask (request request) {var response = wait GetResponse (); Switch (Response status) {Case ResponseStatus.Pending: // wait 2 seconds response = ExecuteTask (request) awaiting; } Return response; } Will the following code be cured?
System. threading. Timer timer; Private async work & lt; Feedback & gt; ExecuteTask (request request) {var response = wait GetResponse (); Switch (response.Status) {case ResponseStatus.Pending: Timer = New System. threading. Timer (async obj = & gt; {response = ExecuteTask (request);}, blank, 1000, system. Threading, timeout, infinite); } Return response; }
In async, you can Task.Delay / p> Private async works & lt; Feedback & gt; ExecuteTask (request request) {var response = wait GetResponse (); Switch (reaction.status) {case repercussor. Delegation: Waiting for the job. Delay (timespace.fresconds (2)) response = awaiting the executed work (request); break; } Return response; }
Comments
Post a Comment