0

I have a Windows forms app which spawns 24 threads, each of which reads data from a text file on a remote server and populates a database with the contents. Each thread loops at a set interval until a flag is changed to stop the data collection.

My problem is that it seems that the FileIO.TextFieldParser call is locking up the UI slightly. Sometimes up to a second or 2. This seems very strange to me but if I remove that part of the code, there is no UI interference. Add it back in and it returns...

EDIT: I've tried it with File.ReadAllLines and it's still happening

Any ideas whats going on here? Also, is there any way to profile the UI thread to confirm that this is/isn't the problem.

Thread spawning is done as follows:

Dim thPoll = New Thread(Sub() mc.CollectData())
thPoll.Name = "ip_" & mc.IP
thPoll.IsBackground = True
thPoll.Priority = ThreadPriority.BelowNormal
thPoll.Start()
doovers
  • 8,545
  • 10
  • 42
  • 70

1 Answers1

1

It probably depends how you run your background threads. The BackgroundWorker for example sends events to the UI thread (see here for an overview). You could try to recode your thread method to use a different threading approach.

You could also try to change the number of threads to see if it has any impact on your ui locking.

Community
  • 1
  • 1
Sascha
  • 1,210
  • 1
  • 17
  • 33
  • I'm not actually using `BackgroundWorker`. I've added the code to my question if you don't mind having a look! – doovers Feb 06 '15 at 08:03
  • Hmm..sorry..no idea. This is wild guess, but could you look at the task manager and resource consumption (like cpu load) and check if you 24 processes consume so many resources, that you whole system might hang? What I could imagine is, that those 24 threads take action at the same instance. If that is the case you could try to limit the number of concurrent update using a Semaphore. – Sascha Feb 06 '15 at 09:35