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
Post a Comment