WPF possible threading issue?
I am creating a application to update a bunch of usb devices at the same time. I have figured out the usb communication with devices just fine but somehow someway I get a threading issue. I am just getting into threading so I just need someone with personal experience on how they would handle this situation.
I have a System.Management object to watch for usb events. When usb connect/disconnect event fires off then check all devices connected by specific usb protocol and look at device paths for PID/VID (specific to manufacturer).
4 Replies
The issue starts when I press button in datagrid that is beside objects listed usb path
Right now the device communication works wonderfully and all files are sent to the device. The application doesn't freeze up since I am using the new thread to actually send the files. HOWEVER I update a ton of devices. (4 at once usually). When all files are sent a the device I have device removed from datagrid so I assume it does not exist anymore and Garbage collecter reclaims the memory. It always happens at the 6th device when I press its update button debugger in visual studio says System.OutofMemoryException and points to threading method of claiming thread.
What I think is happening is that after worker finishes sending files to device the thread is not actually disposed and Visual Studio thinks I am just infinitely trying to claim threads so visual studio yells at me. If I am not implementing threading right please tell me a more proper way to do it! This program has been months in the making by myself trying to figure out USB protocol and file handling. I just want to be able to update all my devices at once!
i dont think you want to dispose the worker immediately after starting the work
also io is inherently async you probably dont need a seperate thread for that
and nowadays we use the TPL
can you show
updateDeviceWithFiles
?can u also give the exact exception, including the stack trace?
reason is OOMEs are not only thrown for the lack of memory (eg
System.Drawing
stuff throws them for invalid/unsupported image formats)The updateDeviceWithFiles gets into the weeds of the program. I actually discovered I was missing an important method of the class I am using with all the dll imports from setupapi.dll in windows. updateDeviceWithFiles goes essentially like this though. I am testing right now with the new function and seeing how it works then will report back here if I still have the same issue