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 .
When separating the business and presentation logic, you need to consider the following: Avoid affinities between the two parts of the application. Be aware of the DPL-restricted API; see Exception conditions for LINK command for details. Be aware of hidden presentation dependencies, such as EIBTRMID usage.
UI components are sometimes messy. If the business logic is tightly coupled with the UI it is often very hard to write proper tests. The only way to make those components testable is by decoupling UI elements from the business logic.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With