.net - AccessViolationException in C# multithreaded form -


first off first c# project. have been working on project 6 months.

we have winforms program , contains logging gui. in order keep rest of program responsive wanted create logging gui on separate thread since can quite intensive when lots of stuff going on.

this how attempted open the form on new gui thread. in general works , keeps main gui responsive. randomly accessviolationexception (http://pastebin.com/7tltbsei) when activated , @ loss.

var thread = new thread(() => {     loggingform = new loggingform(logger.path);     application.run(loggingform); }); thread.name = "loggingformguithread"; thread.start(); 

the logging gui batch reads log file , appends richtextbox. doesn't touch managed code.

you need set apartment state of thread sta.

thread.setapartmentstate(apartmentstate.sta); thread.name = "loggingformguithread"; thread.start(); 

this required many user interface components (such richtextbox) function correctly.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -