asynchronous - C# How do I pass more than just IAsyncResult into AsyncCallback? -


how pass more iasyncresult asynccallback?

example code:

//usage var req = (httpwebrequest)iareq; req.begingetresponse(new asynccallback(iendgetresponse), req);  //method private void iendgetresponse(iasyncresult ia, bool iwantintoo) { /*...*/ } 

i pass in example variable bool iwantintoo. don't know how add new asynccallback(iendgetresponse).

you have use object state pass in. right now, you're passing in req parameter - can, instead, pass in object containing both , boolean value.

for example (using .net 4's tuple - if you're in .net <=3.5, can use custom class or keyvaluepair, or similar):

var req = (httpwebrequest)iareq; bool iwantintoo = true; req.begingetresponse(new asynccallback(iendgetresponse), tuple.create(req, iwantintoo));  //method private void iendgetresponse(iasyncresult ia)  {     tuple<httpwebrequest, bool> state = (tuple<httpwebrequest, bool>)ia.asyncstate;     bool iwantintoo = state.item2;      // use values.. } 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -