c# - Is it dangerous with a while(true) in silverlight? -
i have backgroundworker:
mybackgroundworker.dowork += ((sender, arg) => { while (true) { client.getkfailurescompleted += ((s, e) => { int[] arr = jsonhelper.deserialize<int[]>(e.result); int error = (int)((arr[0] / (double)arr[1]) * 100); debug.writeline("error %: " + error); this.dispatcher.begininvoke(() => { erroroverviewpointcollection.clear(); erroroverviewpointcollection.add(new point(1, 100 - error)); erroroverviewpointcollection.add(new point(1, error)); }); }); client.getfailuresasync(); thread.sleep(5000); } }); and see im running forever. i'm not implementing stop/fail functions stop backgroundworker, need to? if user closes browser application should stop right?
the dowork accesses webservice on completion updates observablecollection databound silverlight application.
if not executing out-of-browser application it's not dangerous. bear in mind non-oob silverlight applications executed in plugin, , once close browser application, plugin closes, , terminates code running in it.
that said, not saying dangerous code execute in oob environment. on safe side should test see if remains alive after close oob silverlight window.
however, best practice replace the
while(true) with
while(bapplicationisalive) and set bapplicationisalive false in event handler of application's exit.
Comments
Post a Comment