473,320 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Presentation Layer vs. Business Logic Layer

I have a windows form that makes a call to my BLL to get some data. The
windows form has a progress bar component that I would like updated as the
data retrieval takes place. However, strictly speaking, the BLL is not
supposed to know anything about the presentation layer. Also, since the
presentation layer has a reference to the BLL, it won't let me add a
reference to the presentation layer from the BLL, it complains about a
"circular dependency".

What's the best way for my BLL to inform my winforms layer about it's
progress and update such in a progress bar?

TIA,

Mike Rodriguez
Nov 16 '05 #1
11 9082
What you could do is create an Event in your BLL that your GUI Layer can
subscribe to to get notification that rows are being read/written in your
BLL layer. Now the BLL layer fires this event but does not have to know
anything about what the receiver of this event is doing with it. This
provides separation between layers. Or you could simply do a timer in the
GUI and start it before the call to the BLL and stop it after the call
returns, and update your progress bar from the timer event.

JIM
"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
I have a windows form that makes a call to my BLL to get some data. The
windows form has a progress bar component that I would like updated as the
data retrieval takes place. However, strictly speaking, the BLL is not
supposed to know anything about the presentation layer. Also, since the
presentation layer has a reference to the BLL, it won't let me add a
reference to the presentation layer from the BLL, it complains about a
"circular dependency".

What's the best way for my BLL to inform my winforms layer about it's
progress and update such in a progress bar?

TIA,

Mike Rodriguez

Nov 16 '05 #2
There are several ways you could do this.

First, have your business logic layer publish an event that it fires
while it's processing the request. The event could contain information
about what the BLL is doing (processing Customer 104423), or how far
along it is in the task it's been given, as a percentage or a count and
a total (100 of 1204), or both a message and a count and total.

Your presentation layer could then create a progress bar and subscribe
to the appropriate event. Every time the BLL fires the event, the
presentation layer updates the progress bar.

A second option is that the BLL publishes a delegate that it promises
to call at intervals during its task. You either pass a delegate method
on the call to the BLL, or you pass null. If you pass a delegate, the
BLL calls it at intervals during its task, passing the same information
as it would have included on the event.

I prefer the second option, personally, as you have to pass the
delegate on the call to the BLL and so the connection between the
delegate method and the task is clearer in your presentation layer.
However, it does lead to messier code in the BLL, which has to pass the
delegate around to where it's needed.

Also note that in both of these cases if you're not using a background
thread for the BLL task then you have to call Application.DoEvents() in
your delegate method in order to redraw the progress bar.

Both of these methods assume that the BLL can indicate meaningful
progress. That is, that most of its time isn't taken up doing one, big
query from a database or something, during which it doesn't have
control of the thread and so cannot call the delegate, then you have to
have a stand-alone progress bar that runs on the UI thread, and run the
BLL in the background thread, with no communication between the two. I
once found an article about how to build a smart progress bar that
"remembers" how long each operation took "last time" and uses that as
an estimate for how fast to progress "this time." Unfortunately, I've
lost it, but I'm sure that Google can dig something like that up fairly
quickly.

Nov 16 '05 #3
You sure DoEvents or a thread is required? I did the following in a button
click on a form, and the progress bar updated just as it should. Seems like
the Value property set must be calling it's paint method when the value
changes.
for (int i = 0; i <= 50000; i++)

{

progressBar1.Value = i;

}
--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Also note that in both of these cases if you're not using a background
thread for the BLL task then you have to call Application.DoEvents() in
your delegate method in order to redraw the progress bar.

Nov 16 '05 #4
Perhaps the ProgressBar class calls DoEvents internally. That would
make sense, considering its purpose.

I was speaking more along the lines of if the OP were to construct his
own progress bar class. I forgot that the framework already supplies
one. :)

Nov 16 '05 #5
I seriously doubt that it would call doevents, doing so would cause issues
for the programmer if not taken into account. For example, if you do some
processing under a button click, doevents would allow the user to click the
button while the processing is going on, and this could cause it to reenter
the processing method.

And besides, only the progress bar paints and not the rest of the form.

--
Thanks
Wayne Sepega
Jacksonville, Fl
"When a man sits with a pretty girl for an hour, it seems like a minute. But
let him sit on a hot stove for a minute and it's longer than any hour.
That's relativity." - Albert Einstein

"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Perhaps the ProgressBar class calls DoEvents internally. That would
make sense, considering its purpose.

I was speaking more along the lines of if the OP were to construct his
own progress bar class. I forgot that the framework already supplies
one. :)

Nov 16 '05 #6

The ProgressBar internally sends a PBM_SETPOS message which
immediately updated the progress bar but it does not process any other
pending windows messages. The result is that the ProgressBar itself
will be responsive but the app as a whole will appear locked up (it
won't react to moving the main form and all other controls will be
non-reactive).

While calling DoEvents will make the app responsive and is better than
nothing, it involves overhead of it's own in identifying and
processing the message loop synchronously. As such, long running
operations such as this are better off moved to a separate thread
where events can be used to update the UI of progress.

Best regards,

Sam
On 3 Mar 2005 11:44:51 -0800, "Bruce Wood" <br*******@canada.com>
wrote:
Perhaps the ProgressBar class calls DoEvents internally. That would
make sense, considering its purpose.

I was speaking more along the lines of if the OP were to construct his
own progress bar class. I forgot that the framework already supplies
one. :)


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.
Nov 16 '05 #7
RCS
But if the background logic was threaded, there would be no need for
DoEvents, because the UI thread would only have an occasional task to do,
that is - update the progress bar.

"Samuel R. Neff" <bl****@newsgroup.nospam> wrote in message
news:5c********************************@4ax.com...

The ProgressBar internally sends a PBM_SETPOS message which
immediately updated the progress bar but it does not process any other
pending windows messages. The result is that the ProgressBar itself
will be responsive but the app as a whole will appear locked up (it
won't react to moving the main form and all other controls will be
non-reactive).

While calling DoEvents will make the app responsive and is better than
nothing, it involves overhead of it's own in identifying and
processing the message loop synchronously. As such, long running
operations such as this are better off moved to a separate thread
where events can be used to update the UI of progress.

Best regards,

Sam
On 3 Mar 2005 11:44:51 -0800, "Bruce Wood" <br*******@canada.com>
wrote:
Perhaps the ProgressBar class calls DoEvents internally. That would
make sense, considering its purpose.

I was speaking more along the lines of if the OP were to construct his
own progress bar class. I forgot that the framework already supplies
one. :)


B-Line is now hiring one Washington D.C. area VB.NET
developer for WinForms + WebServices position.
Seaking mid to senior level developer. For
information or to apply e-mail resume to
sam_blinex_com.

Nov 16 '05 #8
Absolutely: putting long-running tasks in the background is the best
solution. Unfortunately, multi-threading comes with its own set of
problems. I usually prefer to get the app working first before I start
messing around with threads. Then again, maybe I'm just a scaredy-cat.
:-)

Nov 16 '05 #9
Bruce Wood <br*******@canada.com> wrote:
Absolutely: putting long-running tasks in the background is the best
solution. Unfortunately, multi-threading comes with its own set of
problems. I usually prefer to get the app working first before I start
messing around with threads. Then again, maybe I'm just a scaredy-cat.
:-)


I think it's best to design threading in from the start. It's *much*
harder to retro-fit it onto existing code than to work out from the
start what you want the threads to be, where the points of data-sharing
are, etc.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #10
Bruce,

I hadn't thought about the delegate idea. I think I'll try both and see
which one feels better.

Thanks!

Mike
"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
There are several ways you could do this.

First, have your business logic layer publish an event that it fires
while it's processing the request. The event could contain information
about what the BLL is doing (processing Customer 104423), or how far
along it is in the task it's been given, as a percentage or a count and
a total (100 of 1204), or both a message and a count and total.

Your presentation layer could then create a progress bar and subscribe
to the appropriate event. Every time the BLL fires the event, the
presentation layer updates the progress bar.

A second option is that the BLL publishes a delegate that it promises
to call at intervals during its task. You either pass a delegate method
on the call to the BLL, or you pass null. If you pass a delegate, the
BLL calls it at intervals during its task, passing the same information
as it would have included on the event.

I prefer the second option, personally, as you have to pass the
delegate on the call to the BLL and so the connection between the
delegate method and the task is clearer in your presentation layer.
However, it does lead to messier code in the BLL, which has to pass the
delegate around to where it's needed.

Also note that in both of these cases if you're not using a background
thread for the BLL task then you have to call Application.DoEvents() in
your delegate method in order to redraw the progress bar.

Both of these methods assume that the BLL can indicate meaningful
progress. That is, that most of its time isn't taken up doing one, big
query from a database or something, during which it doesn't have
control of the thread and so cannot call the delegate, then you have to
have a stand-alone progress bar that runs on the UI thread, and run the
BLL in the background thread, with no communication between the two. I
once found an article about how to build a smart progress bar that
"remembers" how long each operation took "last time" and uses that as
an estimate for how fast to progress "this time." Unfortunately, I've
lost it, but I'm sure that Google can dig something like that up fairly
quickly.

Nov 16 '05 #11
James,

Thanks for the response! I'll give that a try.

Mike
"James" <no****@hypercon.net> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
What you could do is create an Event in your BLL that your GUI Layer can
subscribe to to get notification that rows are being read/written in your
BLL layer. Now the BLL layer fires this event but does not have to know
anything about what the receiver of this event is doing with it. This
provides separation between layers. Or you could simply do a timer in the
GUI and start it before the call to the BLL and stop it after the call
returns, and update your progress bar from the timer event.

JIM
"Michael Rodriguez" <mi**@nospamforme.com> wrote in message
news:ep**************@TK2MSFTNGP09.phx.gbl...
I have a windows form that makes a call to my BLL to get some data. The
windows form has a progress bar component that I would like updated as the
data retrieval takes place. However, strictly speaking, the BLL is not
supposed to know anything about the presentation layer. Also, since the
presentation layer has a reference to the BLL, it won't let me add a
reference to the presentation layer from the BLL, it complains about a
"circular dependency".

What's the best way for my BLL to inform my winforms layer about it's
progress and update such in a progress bar?

TIA,

Mike Rodriguez


Nov 16 '05 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Learner | last post by:
Hi there, I am just trying to set up 3 tier architecture. When i add my Datalayer project to the Business layer project the methods are exposed to in my business class. But in the similar way when...
1
by: rbg | last post by:
Hi, I am trying to understand the layering concept with the ASP.NET 2.0 apps. I have a ASP.NET 2.0 Web app which has 3 layers Presentation layer which contains UI elements and Input...
16
by: MS newsgroup | last post by:
I don't have clear reasons why we need business logic layer and data logic layer instead of having only data logic layer. Are there any good reasons for that?
2
by: Ily | last post by:
Hi all I am using Visual studio 2005. Im my project I have a presentation layer, a business layer and a data access layer. From my business layer i have a reference to my data layer. I also...
6
by: Dhananjay | last post by:
hello everyone i have got a problem i want to design business layer, data access layer , presentation layer for asp.net using C#.net , can anyone help me to solve this problem. i want some...
0
by: johnlim20088 | last post by:
Can someone help me on this? I need a sample console application built in C# net with new practice -> separate in three layer architecture 1) Presentation layer 2) Business logic layer 3)...
2
by: Chris Zopers | last post by:
Hello, I would like to know what's the best way to implement a business logic layer between my user interface and my database. I would say I'd make a dll-project for the business logic layer...
9
by: SAL | last post by:
Hello, I have a Dataset that I have table adapters in I designed using the designer (DataLayer). I have a business logic layer that immulates the DataLayer which may/may not have additional logic...
2
by: Fresno Bob | last post by:
I have done my first big project with .net 2.0. I like how easy it is to build 3 tier apps with strongly typed datasets and a business logic layer. The main thing I dislike is how to handle...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.