views:

82

answers:

2

I have a three layer application in C#. In business layer i have many threads that do same job . I want to show the progress of each thread on UI , but i don't have the reference of presentation layer .

How can i do this ? What's the best way for this ?

Thanks .

+4  A: 

The simplest way is for the UI to pass the business layer a delegate to call (or an interface) so that it can indicate progress.

This is also really easy to test, because it separates the concerns: in your business layer tests, you can pass in a test delegate and make sure it gets called. In your UI tests, you can fake out the business layer, and pretend that there's progress, calling the appropriate delegate and checking that the UI updates appropriately.

Jon Skeet
+6  A: 

The most appropriate answer here is probably to expose an event somewhere on your business layer. Your UI code can subscribe to the event, and handle the event by switching to the UI thread (if necessary) and update itself.

Then the business code doesn't need to know about the UI, and can work the same without any UI (but as with all delegates / callbacks, you need to check for null before attempting to invoke the delegate).

Marc Gravell