473,387 Members | 1,597 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,387 software developers and data experts.

Thread management in .NET (Business logic and UI)


Hi,

I am writing an application that has its UI and Logic layers. My
initial idea was to launch the two layers on two different threads and
manage calls made by the UI to the Logic manually. Which means
handling the Sleep/Wakeup of the logic thread all by myself. This
looks reasonable to me in the way that the UI and the Logic run
separately and only send messages to each other. The main disadvantage
of thos method is that I have to manage my threads/locks by myself.

A friend of mine advised me to avoid the thread handling and use the
Invoke mechanism instead. I don't really like the idea because it
breaks the logical flow and the structure of the program. In addition
I still have to implement the various locks.

The Logic layer basically has serial flow and does not require multi
threading except when interacting with the UI.

I would be happy to hear you comments.

Mar 20 '07 #1
5 5997
This would be overkill for serial operations. If the operations are
short-lived, then just use the ThreadPool class and call the
QueueUserWorkItem method, passing a delegate which points to the code you
want to execute on a thread from the thread pool. Then, you can have that
code call the Invoke method when you need to perform UI updates (assuming
that you need to update the UI from that logic).

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"salberts" <al***************@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
>
Hi,

I am writing an application that has its UI and Logic layers. My
initial idea was to launch the two layers on two different threads and
manage calls made by the UI to the Logic manually. Which means
handling the Sleep/Wakeup of the logic thread all by myself. This
looks reasonable to me in the way that the UI and the Logic run
separately and only send messages to each other. The main disadvantage
of thos method is that I have to manage my threads/locks by myself.

A friend of mine advised me to avoid the thread handling and use the
Invoke mechanism instead. I don't really like the idea because it
breaks the logical flow and the structure of the program. In addition
I still have to implement the various locks.

The Logic layer basically has serial flow and does not require multi
threading except when interacting with the UI.

I would be happy to hear you comments.

Mar 20 '07 #2
In .NET 2.0 and later, take a look at the Background worker class. It's
designed for this type of processing.

Mike Ober.

"salberts" <al***************@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
>
Hi,

I am writing an application that has its UI and Logic layers. My
initial idea was to launch the two layers on two different threads and
manage calls made by the UI to the Logic manually. Which means
handling the Sleep/Wakeup of the logic thread all by myself. This
looks reasonable to me in the way that the UI and the Logic run
separately and only send messages to each other. The main disadvantage
of thos method is that I have to manage my threads/locks by myself.

A friend of mine advised me to avoid the thread handling and use the
Invoke mechanism instead. I don't really like the idea because it
breaks the logical flow and the structure of the program. In addition
I still have to implement the various locks.

The Logic layer basically has serial flow and does not require multi
threading except when interacting with the UI.

I would be happy to hear you comments.

Mar 20 '07 #3
salberts <al***************@gmail.comwrote:
I am writing an application that has its UI and Logic layers. My
initial idea was to launch the two layers on two different threads and
manage calls made by the UI to the Logic manually.
Why? I don't see any benefit in introducing threading here.
A friend of mine advised me to avoid the thread handling and use the
Invoke mechanism instead.
Well, you certainly need to use extra threads for long-running
operations (assuming it's a WinForms app) but that doesn't actually
"avoid" thread handling.
The Logic layer basically has serial flow and does not require multi
threading except when interacting with the UI.
In that case don't introduce threading artificially. Life is hard
enough without adding complexity for no benefit :)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 20 '07 #4
"salberts" <al***************@gmail.comwrote in message
news:11**********************@y66g2000hsf.googlegr oups.com...
>
Hi,

I am writing an application that has its UI and Logic layers. My
initial idea was to launch the two layers on two different threads and
manage calls made by the UI to the Logic manually. Which means
handling the Sleep/Wakeup of the logic thread all by myself. This
looks reasonable to me in the way that the UI and the Logic run
separately and only send messages to each other. The main disadvantage
of thos method is that I have to manage my threads/locks by myself.

A friend of mine advised me to avoid the thread handling and use the
Invoke mechanism instead. I don't really like the idea because it
breaks the logical flow and the structure of the program. In addition
I still have to implement the various locks.

The Logic layer basically has serial flow and does not require multi
threading except when interacting with the UI.

I would be happy to hear you comments.
The real art of multi-threading is how to avoid them as much as possible, if you can't, for
instance if you don't want to freeze the UI while executing a long running task, or (and) if
you *can* take advantage of some form of parallelism offered by running multiple threads ,
then the art is to use them sparingly/wisely.
From your description I don't see the need to introduce threads, unless the "Logic Layer"
falls into the category of long running tasks.

Willy.

Mar 20 '07 #5
On Mar 20, 10:07 pm, Jon Skeet [C# MVP] <s...@pobox.comwrote:
salberts<albert.achtenb...@gmail.comwrote:
I am writing an application that has its UI and Logic layers. My
initial idea was to launch the two layers on two different threads and
manage calls made by the UI to the Logic manually.

Why? I don't see any benefit in introducing threading here.
A friend of mine advised me to avoid the thread handling and use the
Invoke mechanism instead.

Well, you certainly need to use extra threads for long-running
operations (assuming it's a WinForms app) but that doesn't actually
"avoid" thread handling.
The Logic layer basically has serial flow and does not require multi
threading except when interacting with the UI.

In that case don't introduce threading artificially. Life is hard
enough without adding complexity for no benefit :)

--
Jon Skeet - <s...@pobox.com>http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Hi,

First of all thanks for all the quick replies. I think I understand
the direction all who replied is heading to. I just want to clarify
what my program does.

The "Logic" is a process (not the operation system term) that does
some computational work. Its interaction with the UI is done to
accomplish three main tasks:

1. Send output to the user.
2. Ask for input from the user. And later on recieve the input
response.
3. Receive command from user (such as back, finish, terminate, etc)

So it is a continuous work flow and not a bunch of separated
computational actions such as DoTransaction(). In addition since the
input request/response is done asynchronously in any case, I have to
synchronize this scenario. So I think that adding a small thread
control mechanism here (in some kind of a mediator classof course)
would be quite easy and will make the work flow more intuitive and
easier to understand and debug.

Albert

Mar 21 '07 #6

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

Similar topics

0
by: Scott Abel | last post by:
For immediate release: The Rockley Group Content Management Workshop Series Coming to Atlanta, Seattle, Vancouver, Chicago, Washington, DC, Toronto, and Research Triangle Park Learn more:...
4
by: Simon Harvey | last post by:
Hello Chaps, Me and a collegue have been talking about where the best place to put business logic is. I think that the best place is where Microsoft suggest - in a seperate business logic...
1
by: Abelardo Vacca | last post by:
Hello, I am currently in the process of switching our application to a N-Tier model with .NET. One of the aspects we want ot get right from the start not to worry about it after is the...
1
by: William Sullivan | last post by:
I'm trying to nail down some issues with the cache in my application. Currently, I have an object that stands between my business logic and database logic called CacheLogic (cute, no?). ...
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?
10
by: Henrik Dahl | last post by:
Hello! I have some images (for instance in .jpg files) which I would like to apply digital rights management for, i.e. that only authorized users may wiew then using their www browser, i.e. if a...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.