Click here to Skip to main content
15,900,108 members
Home / Discussions / Visual Basic
   

Visual Basic

 
QuestionCrystal Reports deployment Pin
Jodd23-Apr-08 12:19
Jodd23-Apr-08 12:19 
GeneralRe: Crystal Reports deployment Pin
Steven J Jowett23-Apr-08 12:33
Steven J Jowett23-Apr-08 12:33 
GeneralRe: Crystal Reports deployment Pin
Jodd23-Apr-08 13:29
Jodd23-Apr-08 13:29 
GeneralDeveloping applications for BlackBerry Pin
Mr Oizo23-Apr-08 4:50
Mr Oizo23-Apr-08 4:50 
GeneralRe: Developing applications for BlackBerry Pin
Thomas Stockwell23-Apr-08 8:24
professionalThomas Stockwell23-Apr-08 8:24 
QuestionError QueryInterface while trying to use VB6 DLL into VB.NET project Pin
mandrake_223-Apr-08 4:45
mandrake_223-Apr-08 4:45 
Questionsetting a variable for multiple threads Pin
Tom Deketelaere23-Apr-08 4:23
professionalTom Deketelaere23-Apr-08 4:23 
GeneralRe: setting a variable for multiple threads Pin
Luc Pattyn23-Apr-08 11:04
sitebuilderLuc Pattyn23-Apr-08 11:04 
Hi,

I'm afraid you are confusing a couple of things.

1.
the Shared keyword in VB.NET indicates a variable is a class member, rather than an
instance member, i.e. it exists once in the class, as opposed to once in every instance
of that class. The C# equivalent is "static". It has no relationship with threads.

2.
all variables by default are thread-agnostic, they exist once and are readable by all
threads.

3.
The one problem you may have is that variables could get "cached" in local variables
(that requires explicit code to do it) or in CPU registers, which could result in one
of the threads using stale data, i.e. not accessing the memory-based variable every time
your code seems to indicate.Example (in C#):

int a=1;
for (int i=0; i< 10; i++) {
    int b=a+1;
}

although the code seems to access variable a over and over, maybe it gets executed
as a single read of a, and the value gets stored somewhere (in a register).
The compiler is allowed to do that under some circumstances, and there are ways to
prevent it. Good old C had the volatile keyword to prevent such optimisations;
C# has the same volatile keyword.
According to ms-help://MS.VSCC.v90/MS.msdnexpress.v90.en/dv_vsref/html/7c0efba1-45d9-4798-9051-9bdca3b899a6.htm VB.NET does not have an equivalent.

4.
There are language-specific keywords and thread synchronization primitives/classes
that may help you in achieving what you need. Have a look at SyncLock (that should do it),
and Interlocked class.

Smile | :)
same.

Luc Pattyn [Forum Guidelines] [My Articles]

This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.


GeneralRe: setting a variable for multiple threads Pin
Tom Deketelaere23-Apr-08 23:10
professionalTom Deketelaere23-Apr-08 23:10 
GeneralFile Open/Close Pin
ritz123423-Apr-08 3:06
ritz123423-Apr-08 3:06 
GeneralRe: File Open/Close Pin
Dave Kreskowiak23-Apr-08 3:38
mveDave Kreskowiak23-Apr-08 3:38 
GeneralRe: File Open/Close Pin
ritz123423-Apr-08 4:32
ritz123423-Apr-08 4:32 
GeneralRe: File Open/Close Pin
Dave Kreskowiak23-Apr-08 9:59
mveDave Kreskowiak23-Apr-08 9:59 
GeneralProblem in bring a checkbox inside a datagrid in windows application.. Pin
Balagurunathan S23-Apr-08 1:14
Balagurunathan S23-Apr-08 1:14 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
darkelv23-Apr-08 1:17
darkelv23-Apr-08 1:17 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
Balagurunathan S23-Apr-08 1:27
Balagurunathan S23-Apr-08 1:27 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
darkelv23-Apr-08 1:38
darkelv23-Apr-08 1:38 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
Balagurunathan S23-Apr-08 1:44
Balagurunathan S23-Apr-08 1:44 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
darkelv23-Apr-08 1:56
darkelv23-Apr-08 1:56 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
Balagurunathan S23-Apr-08 2:06
Balagurunathan S23-Apr-08 2:06 
GeneralRe: Problem in bring a checkbox inside a datagrid in windows application.. Pin
darkelv23-Apr-08 2:15
darkelv23-Apr-08 2:15 
Questionstring Replace in vb.net Pin
RajeevKumarSharma23-Apr-08 0:54
RajeevKumarSharma23-Apr-08 0:54 
GeneralRe: string Replace in vb.net Pin
Christian Graus23-Apr-08 1:06
protectorChristian Graus23-Apr-08 1:06 
GeneralRe: string Replace in vb.net Pin
RajeevKumarSharma23-Apr-08 1:28
RajeevKumarSharma23-Apr-08 1:28 
GeneralRe: string Replace in vb.net Pin
Dave Kreskowiak23-Apr-08 3:34
mveDave Kreskowiak23-Apr-08 3:34 

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.