Sunday, 15 August 2010

c# - Thread Start causing OOM Exception -



c# - Thread Start causing OOM Exception -

thread splashscreenthread = new thread(new parameterizedthreadstart(displaysplashscreen)); splashscreenthread.setapartmentstate(apartmentstate.sta); splashscreenthread.isbackground = true; splashscreenthread.start(modulename);

the above code after beingness executed 30 50 times crashes outofmemoryexception.

if seek splashscreenthread.join when displaysplashscreen function closes, application hangs.

update:

development machine 64 bit machine , application under question 32 bit wpf application using prism.

everytime module opening splash window shown. when module has opened splash window closed.

private void displaysplashscreen(object modulename) { if (modulename != null) splashscreen = new splashwindow(modulename.tostring(), this.splashscreendescription); else splashscreen = new splashwindow(string.empty, string.empty); splashscreen.showdialog(); }

note: splashwindows custom window shown , closed later automatically.

module loading start , loaded end fns:

private void moduleloadingstart(object modulename) { if (this.moduleloadingvisibility != visibility.visible) { this.moduleloadingvisibility = visibility.visible; // spawn off new thread thread splashscreenthread = new thread(new parameterizedthreadstart(displaysplashscreen)); splashscreenthread.setapartmentstate(apartmentstate.sta); splashscreenthread.isbackground = true; splashscreenthread.start(); } } private void moduleloadingend() { if (this.moduleloadingvisibility != visibility.collapsed) { this.moduleloadingvisibility = visibility.collapsed; while (true) { if (splashscreen == null) thread.sleep(100); else break; } closesplashscreendelegate mydel = new closesplashscreendelegate(splashscreen.close); splashscreen.dispatcher.invoke(mydel, null); } }

what missing here?

wtf instantiating many threads for?! know threads memory hungry beasts. each 1 takes many megabytes of continuous ram!

anyways.

if seek splashscreenthread.join when displaysplashscreen function closes, application hangs.

this pretty simple diagnose. problem here have gotten thread.join wrong.

the point of thread.join block (stop , wait) current thread until work on other thread complete. issue here splashscreenthread in loop. looping on display code. never complete. hence have told main thread wait , nil until forever.

c# multithreading out-of-memory prism

No comments:

Post a Comment