c# - Elegant retry on effectively arbitrary call -



c# - Elegant retry on effectively arbitrary call -

i have phone call remote resource, on occasion wcf 1 have similar problem com phone call might useful.

i want retry phone call if exceptions thrown , there dozen or calls want handle more elegantly.

i thought of reflection vampire instinctively shy away it.

this have

void mycall(){ (int = 0; < 5; i++) { seek { homecoming this.innerproxy.loadmap2(mapname); } grab (servertoobusyexception e) { logger.debugformat("caught servertoobusyexception {0}th time retrying [{1}]", + 1, e.message); thread.sleep(50); } } // final phone call fail if servertoobusy thorwn here. homecoming this.innerproxy.loadmap2(mapname); }

as have several calls seems ought able pass in method pointer , parameter array 'pattern'.

any suggestions?

this indeed relatively easy in c# using delegate. can utilize func<t> without parameters, since can specify arbirary number of parameters using lambda closure:

t retry<t>(func<t> method, int n) { (int = 0; < n - 1; i++) { seek { t value = method(); homecoming value; } grab (servertoobusyexception e) { //... } } //final phone call homecoming method(); }

and calling method:

void mycall() { var result = retry(() => this.innerproxy.loadmap2(mapname), 5); }

note mycall returns void, don't think does, since seem homecoming values. if want homecoming void instead, utilize action instead of func<t> parameter.

c# .net

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -