c# - How to create an IAsyncResult that immediately completes? -


i implementing interface requires implementations of begindosomething , enddosomething methods. dosomething isn't long-running. simplicity assume dosomething compares 2 variables , return whether > b

so begindosomething should like:

protected override iasyncresult begindosomething(int a, int b, asynccallback callback, object state) {      bool returnvalue = > b;      return ...; //what should return here?        //the method completed , don't need wait  } 

i don't know should return. implement begindosomething because have to, not because method long-running. need implement own iasyncresult? there implementation in .net libraries?

the quick hack way of doing use delegate:

protected override iasyncresult begindosomething(int a, int b, asynccallback callback, object state) {      bool returnvalue = > b;      func<int,int,bool> func = (x,y) => x > y;      return func.begininvoke(a,b,callback,state); } 

the downside of approach, need careful if 2 threads calling method concurrently you'll error.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -