• 0

[C# WPF] UI Locking when more than 2 Threads.


Question

So at the minute i'm having quite the Problem with my Multi-Threaded App.

I get a list of things to complete, on each iteration of the loop I create a new instance of a class to process the data, each class containing a BackgroundWorker.

The problem is all of the threads dont seem to run at the same time, and I can only get 2 of the class instances to run at any one time. The List is also bound to a DataGrid indicating the progress of each operation.

Also, due to the Threads not all running at the same time, I also have the option to select an option in list and start the process. Starting the process keeps the other threads running but the UI locks up until one of the thread completes.

The code contained within the UI thread is pretty light-weight so i'm unsure as to why i'm getting lock ups.

I can't provide any code for this i'm afraid but I would appreciate places to look in the code and also tips on isolating the problem.

Cheers,

MiG

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

i would guess that the UI is trying to access data that the other thread(s) are using. If you have done some sort of semiphore/mutual exclusion, i would look there. I am guessing that one of the threads are not giving up the "key" until it exits.

Link to comment
Share on other sites

  • 0
i would guess that the UI is trying to access data that the other thread(s) are using. If you have done some sort of semiphore/mutual exclusion, i would look there. I am guessing that one of the threads are not giving up the "key" until it exits.

Cheers, think i've just figured out what the problem is! :)

Link to comment
Share on other sites

  • 0
Cheers, think i've just figured out what the problem is! :)

What was the solution? (For other people with similar probs) :)

Link to comment
Share on other sites

  • 0
What was the solution? (For other people with similar probs) :)

Not looked at the code yet... but I think its due to locking resources on a WebService that im contacting in each Thread.

I'll get to look at it monday.

Cheers,

MiG

Link to comment
Share on other sites

  • 0

Ive got a solution for this....I came accross the same problem when working on a project before.

				Dispatcher.Invoke(DispatcherPriority.Send,
								  new System.Threading.ThreadStart(
									   () =>
									   MethodName(params)
									);

Use that within the BackgroundWorker thread to access the main UI thread. Obviously change "MethodName" and "params" to what you need... :D

GE

Link to comment
Share on other sites

  • 0

So, i've managed to get the program not locking up now, but I'm having problems with my WebService in that it "queues" operations up, with only parsing one at time.

Say I click a button to start an operation, it fires, but the webService method doesn't return till there is less than two user created threads running.

The webService methods are firing asynchronously so i'm not entirely sure why this is happening.

Any ideas?

Cheers,

MiG

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.