c# - Async and Await : Error In MVC -
hi have problem use async , wait in following method. used neevia converter convert document , want wait method until conversion completed.
could please help:
public void asyncandwaittillexecutionmethod(string filename) { callforconverter(filename); } private async void callforconverter(string filename) { var result = await callforconverterasync(filename); } private task<string> callforconverterasync(string filename) { string fromlocation; string tolocation; // data source string filefullname = filename; fromlocation = "abc"; tolocation = "xyz"; return task.factory.startnew(() => convertusingneevia(fromlocation, tolocation)); } private string convertusingneevia(string from, string to) { string success = "false"; int timeout = 3000; try { neevia.docconverter nvdc = new neevia.docconverter(); int res = nvdc.convertfile(from, to, timeout); } catch (exception ex) { throw new exception("exception ", ex); } success = "true"; return success; }
it giving me following error callforconverter() method. asynchronous operation cannot started @ time. asynchronous operations may started within asynchronous handler or module or during events in page lifecycle in mvc...
just remove async
, await
, , (the horrible) startnew
code:
public void asyncandwaittillexecutionmethod(string filename) { string fromlocation; string tolocation; // data source string filefullname = filename; fromlocation = "abc"; tolocation = "xyz"; convertusingneevia(fromlocation, tolocation); }
Comments
Post a Comment