Question Multithreading App Blocking UI

doovers

Member
Joined
Aug 3, 2014
Messages
5
Programming Experience
1-3
I've been trying for about 3 months now to write a multithreaded app to collect data from multiple machines in a machine shop and insert the data into a database. There are 87 machines, 48 of which dump their data into text files on a network drives, and 39 of which that can be polled for data with an API. I've written a class to use the API and handle all the data collection from those machines and a second class to read the text files and parse the contents, 1 line of comma separated values (4kb file size). The data from both sources is identical so each of the two classes inherit a parent class which serves as a container for all the machine properties. I want to create a separate instance of the appropriate class for each machine and have them loop collection and updating of the database at a set interval potentially indefinitely. The main form has a DataGridView bound to the database containing the machine data, and start, stop buttons.


The main problem encountered would be for a network drive or a machine to be offline which causes a dramatic increase in collection time so it's necessary that each machine is updated independent to the rest.


I've tried so many different approaches that it would be impossible to post them all here but in summary, I've tried the following techniques:


- Spawning 87 threads, 1 for each machine (I've since read that this is a poor approach)
- Threadpools
- BackgroundWorkers
- Tasks & Async/Await


However it's very possible that I failed to implement the techniques I tried correctly


Unfortunately, nothing I have tried has offered an acceptable user experience. Despite my best efforts the UI locks up and/or the app goes into a 'Not Responding' state until it eventually crashes.


I'm sure there has to be a way to achieve this as it's not a hugely complicated app.


I'd appreciate any advice, help or guidance anyone can offer as I'm at the end of my tether with this project :(


If code samples for any of my efforts would be of benefit, please let me know and I'll post them.


Thanks in advance!!
 

doovers

Member
Joined
Aug 3, 2014
Messages
5
Programming Experience
1-3
The API returns an offline message after a specified timeout. This timeout needs to be >10secs to ensure the connection is made for online machines.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,397
Location
Sydney, Australia
Programming Experience
10+
About once every 5-8 seconds

To be clear, you mean that you need to poll all 89 every 5-8 seconds rather than just one of the 89, right? How long does it take to process a file and to process a machine, assuming everything is online? How are you currently determining that a network drive is offline? If a machine or drive is offline, do you still check it again after 5-8 seconds or do you ignore it for a while?
 

doovers

Member
Joined
Aug 3, 2014
Messages
5
Programming Experience
1-3
Yes all 89 machines to be polled every 5-8 secs. With a view to providing a 'Current State' type dashboard. Wrt processing times, when everything is online, about 3 secs with API and less for a file. At the moment I'm relying on File.OpenText to return a "The network path was not found." error and handling that. I'm not ignoring it for any length of time just continuing with the loop.
 
Top Bottom