my requirement have send list of brokered messages azure service bus asynchronously. not able implement sendbatchasync method properly. let me explain in detail. here code:
public async task sendbatchenrollmentmessages() { while(somevalue) { //logic fetch data sql db through stored proc list of brokered message i.e. messagelist if(messagelist.count() > 0) { await sender.sendmessagesasync(messagelist); } //some more logic somevalue } }
where sendmessageasync logic :
public async task sendmessagesasync(list<brokeredmessage> brokeredmessagelist) { var topicclient = createtopicclient(); await topicclient.sendbatchasync(brokeredmessagelist); }
my issue when debug application using break point, compiler comes till await topicclient.sendbatchasync(brokeredmessagelist);
, exits code i.e application debuggin completed. doesn't return while condition. instead of using sendbatchasync if use sendbatch, works fine. doing wrong?
solution: issue test method calling above funciton. of type void. should have been of type async task. big ned stoyanov helping me out in this.
an async
method returns when after encounters await
statement , sets asynchronous operation being awaited. rest of method continues after await
finished.
you can't step through async
methods that, try putting breakpoint after await
, should hit when asynchronous call completes.
alternatively may have deadlock, see post ways avoid it.
as mentioned in our discussion unit test needs async
well, return task
, await
async
calls
[testmethod] public async task sendregionsenrollmentmessages() { eventmanager eventmgr = new eventmanager(clienturn, programurn, "cw"); await eventmgr.sendbatchevents(eventtype.enrollment); }
Comments
Post a Comment