basically need make remote request using vendor's .net sdk information. sdk has no async implementations on methods trying come on own. bascially want fire off request synchronous method, , wait on amount of time. if request takes long, need act , report down client in our web app.
i'm wondering if best way this, or there better way? code below service method called controller action.
public async task<bool> signersadded(string packageid) { var timeout = 5000; var task = task.run(() => { var package = _eslclient.getpackage(new packageid(packageid)); return package != null && package.documents.values.any(x => x.signatures.any()); }); var stopwatch = stopwatch.startnew(); while (!task.iscompleted) { if (stopwatch.elapsedmilliseconds >= timeout) return false; } return false; }
task.wait has overload takes int defines timeout.
public task<bool> signersadded(string packageid) { var timeout = 5000; var task = task.run(() => { var package = _eslclient.getpackage(new packageid(packageid)); return package != null && package.documents.values.any(x => x.signatures.any()); }); if(!task.wait(1000 /*timeout*/)) { // timeout return false; } return task.result; }
Comments
Post a Comment