I am working on an application which has a main windows form with a timer (actually 2 timers but I want to get 1 working 1st). The form has a form-level property which I store an instance of a class which calls functions in an unmanaged c++ assembly.
Initially, I had a button on the form which would create a new instance of the class and store it in the form-level property and make a call to the unmanaged code then start a timer. The timer would then, at it's specified interval, also reference the
form-level property and making it's own calls to the unmanaged code. This caused issues including the lovely blue screen of death. I assume this was because I had instanciated the class at the form level in the form's thread and then the timer
in it's thread was also trying to use the form-level property which was instanciated in a thread that was not the timer's thread. At this point I changed my timer tick method to create a new instance of the necessary class and store that to the form-level
property. This still seems to be causing issues as well. Not knowing that much about threading I'm a little lost on how best to organize my code. Any guidance?
View Complete Post