Click here to Skip to main content
15,919,178 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralProgram Files Nightmare Pin
Dreamer20075-Jan-08 1:43
Dreamer20075-Jan-08 1:43 
GeneralRe: Program Files Nightmare Pin
nlarson115-Jan-08 3:45
nlarson115-Jan-08 3:45 
GeneralRe: Program Files Nightmare Pin
Dave Kreskowiak5-Jan-08 15:14
mveDave Kreskowiak5-Jan-08 15:14 
GeneralRe: Program Files Nightmare Pin
Dreamer20076-Jan-08 19:32
Dreamer20076-Jan-08 19:32 
GeneralRe: Program Files Nightmare Pin
Dave Kreskowiak7-Jan-08 3:01
mveDave Kreskowiak7-Jan-08 3:01 
QuestionWhen do and where do i decide i need to adopt threading if at all ??? Pin
vbbeg4-Jan-08 20:37
vbbeg4-Jan-08 20:37 
AnswerRe: When do and where do i decide i need to adopt threading if at all ??? Pin
Guffa5-Jan-08 7:32
Guffa5-Jan-08 7:32 
AnswerRe: When do and where do i decide i need to adopt threading if at all ??? Pin
Luc Pattyn5-Jan-08 11:08
sitebuilderLuc Pattyn5-Jan-08 11:08 
Hi,

multi-threading is all about performance; there are two reasons to add some threads
(although these reasons often converge):

1. overall behavior
to increase parallellism: you want several things to go on at the same time, without
one affecting the other more than necessary (they inherently interfere with each other
because of limited resources, such as CPU cycles or memory bandwidth).
So you add threads to decouple logically distinct activities.

Example: one thread can do a database access, another an Internet fetch, yet another
a complex computation. It would not make much sense to let the database activity wait
on an unrelated Internet reply or an unrelated computation.

The most obvious wish for parallellism is in the GUI: you want to be able to
move, resize, close, ... your form(s) at all times, don't you? Therefore an interactive
application should reserve one thread (normally the main thread, also called GUI thread)
for dealing with the GUI, the windows messages, etc; all actual operations (database,
betwork, calculations) should be delegated to threads.


2. fastest execution
to improve performance: if you want a process to be completed as soon as possible,
then it does not make sense to have system resources (CPU power, bus bandwidth, ...)
less active than they could be, i.e. you want to have maximum chance of code being ready
for execution. Having only one thread to execute all code often is not the right way then.

With this in mind you might consider adding threads to execute identical jobs, each handling
part of the data. For performance reasons this typically does not help beyond a few threads,
since they would compete with each other for system resources (there is only so much a disk
or a network can offer). If the actual bottleneck is CPU power, then I would recommend
not to exceed 2*Environment.ProcessorCount

Final comments:

1.
multi-threading always needs thread synchronization and/or interthread communication;
you can not just have a number of threads working on shared data without protecting the
data from becoming inconsistent; the Thread class, as well as mutexes, locks, and the like
will support this.

2.
the GUI Controls are not thread-safe; Windows requires that a Control only be accessed
by the thread that created it (normally the GUI thread for all of them, since they typically
are all linked in one big hierarchy). When other threads need to report and show some
results using the GUI, there is an Invoke mechanism, supported by Control.InvokeRequired
and the methods Control.Invoke() or BeginInvoke() methods.

3.
threads are either foreground or background; all foreground threads must finish before
your app can exit. As a result it often is best to use background threads for things
that should go on in the background and not prevent an app from exiting.

Smile | :)

Luc Pattyn [Forum Guidelines] [My Articles]

Happy 2008!


GeneralRe: When do and where do i decide i need to adopt threading if at all ??? Pin
vbbeg5-Jan-08 22:47
vbbeg5-Jan-08 22:47 
GeneralRe: When do and where do i decide i need to adopt threading if at all ??? Pin
Luc Pattyn6-Jan-08 2:59
sitebuilderLuc Pattyn6-Jan-08 2:59 
QuestionHow to suppress a column in datagrid? (vb.net 1.1) Pin
infotools4-Jan-08 20:23
infotools4-Jan-08 20:23 
GeneralRe: How to suppress a column in datagrid? (vb.net 1.1) Pin
ejaz_pk4-Jan-08 21:48
ejaz_pk4-Jan-08 21:48 
GeneralRe: How to suppress a column in datagrid? (vb.net 1.1) Pin
infotools6-Jan-08 3:00
infotools6-Jan-08 3:00 
GeneralRe: How to suppress a column in datagrid? (vb.net 1.1) Pin
DigiOz Multimedia5-Jan-08 8:43
DigiOz Multimedia5-Jan-08 8:43 
GeneralRe: How to suppress a column in datagrid? (vb.net 1.1) Pin
Dayekh5-Jan-08 19:39
Dayekh5-Jan-08 19:39 
GeneralDisplay Design HTML Pin
Socheat.Net4-Jan-08 16:16
Socheat.Net4-Jan-08 16:16 
GeneralRe: Display Design HTML Pin
LloydA1114-Jan-08 16:23
LloydA1114-Jan-08 16:23 
GeneralRe: Display Design HTML Pin
Socheat.Net4-Jan-08 17:31
Socheat.Net4-Jan-08 17:31 
GeneralRe: Display Design HTML Pin
LloydA1114-Jan-08 23:53
LloydA1114-Jan-08 23:53 
QuestionStopping a form from appearing in VB.NET? Pin
LloydA1114-Jan-08 14:39
LloydA1114-Jan-08 14:39 
AnswerRe: Stopping a form from appearing in VB.NET? Pin
nlarson115-Jan-08 3:40
nlarson115-Jan-08 3:40 
GeneralRe: Stopping a form from appearing in VB.NET? Pin
LloydA1115-Jan-08 3:46
LloydA1115-Jan-08 3:46 
GeneralRe: Stopping a form from appearing in VB.NET? Pin
Luc Pattyn5-Jan-08 4:34
sitebuilderLuc Pattyn5-Jan-08 4:34 
QuestionAvoiding Hardcoded Values Pin
caalock4-Jan-08 6:53
caalock4-Jan-08 6:53 
GeneralRe: Avoiding Hardcoded Values Pin
Paul Conrad4-Jan-08 7:12
professionalPaul Conrad4-Jan-08 7:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.