c# - How to check message arrival in service bus at every 20 seconds? -
i using service bus of azure hold list of messages means messages can enter in service bus @ time.
so want keep watch on service bus check whether message there in service or not.it want keep watch on service bus regarding message arrival in service bus @ interval 0f 20 seconds.
in every 20 seconds check message arrival in service bus , want perform in background asynchronously.
i want call below method in every 20 seconds in background:
private static void receivemessages() { // peeklock mode (default) applications require "at least once" delivery of messages subscriptionclient agentsubscriptionclient = subscriptionclient.create(topicname, "agentsubscription"); brokeredmessage message = null; while (true) { try { //receive messages agent subscription message = agentsubscriptionclient.receive(timespan.fromseconds(5)); if (message != null) { console.writeline("\nreceiving message agentsubscription..."); console.writeline(string.format("message received: id = {0}, body = {1}", message.messageid, message.getbody<string>())); // further custom message processing go here... message.complete(); } else { //no more messages in subscription break; } } catch (messagingexception e) { if (!e.istransient) { console.writeline(e.message); throw; } else { handletransienterrors(e); } } } // receiveanddelete mode, applications require "best effort" delivery of messages subscriptionclient auditsubscriptionclient = subscriptionclient.create(topicname, "auditsubscription", receivemode.receiveanddelete); while (true) { try { message = auditsubscriptionclient.receive(timespan.fromseconds(5)); if (message != null) { console.writeline("\nreceiving message auditsubscription..."); console.writeline(string.format("message received: id = {0}, body = {1}", message.messageid, message.getbody<string>())); // further custom message processing go here... } else { console.writeline("\nno more messages in subscription"); //no more messages in subscription break; } } catch (messagingexception e) { if (!e.istransient) { console.writeline(e.message); throw; } } } agentsubscriptionclient.close(); auditsubscriptionclient.close(); }
so can tell me how call above method every 20 seconds?
the beginner-friendly solution is:
drag timer toolbox, give name, set desired interval , set "enabled" true. double click timer , visual studio (or whatever using) write following code:
private void wait_tick(object sender, eventargs e) { refreshtext(); //add method want call here. }
or this
private timer timer1; public void inittimer() { timer1 = new timer(); timer1.tick += new eventhandler(timer1_tick); timer1.interval = 2000; // in miliseconds timer1.start(); } private void timer1_tick(object sender, eventargs e) { isonline() }
Comments
Post a Comment