473,569 Members | 3,063 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6018
This would be overkill for serial operations. If the operations are
short-lived, then just use the ThreadPool class and call the
QueueUserWorkIt em 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.co m

"salberts" <al************ ***@gmail.comwr ote in message
news:11******** **************@ y66g2000hsf.goo glegroups.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.comwr ote in message
news:11******** **************@ y66g2000hsf.goo glegroups.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.comwr ote:
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.co m>
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.comwr ote in message
news:11******** **************@ y66g2000hsf.goo glegroups.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.com wrote:
salberts<albert .achtenb...@gma il.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
2123
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: http://www.rockley.com/workshops.htm The Rockley Group Content Management Workshop Series is designed to
4
2244
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 layer. The alternative is to have all the logic in with the business entity objects, thus eliminating the business logic layer. The reason that I...
1
1841
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 Exception management. I have read two MSDN documents that appear to be in contradiction, and I would like to know if someone can explain to me which of...
1
2695
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?). Global.asax.cs creates it in Application_Start, initializes it and places it in the cache. During initialization, CacheLogic retrieves data from the DB logic...
16
9009
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
3143
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 non-authorized user is attempting to address the .jpg file with a url, or for that sake gets a copy of the image file from an authorized user, the...
2
4053
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 and make classes that represent objects/tables. For example, if I have a table named 'tblPersons' I would make a class named 'clsPersons' and a class...
9
2724
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 in. My business classes are, of course, decorated with the: <System.ComponentModel.DataObject() attribute. So, I drop a GridView on a webform...
0
7703
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7619
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8138
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6290
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5228
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3662
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
950
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.