Click here to Skip to main content
15,895,084 members
Home / Discussions / C#
   

C#

 
GeneralRe: Updating Primary Key Pin
serene joey5-Nov-07 20:44
serene joey5-Nov-07 20:44 
GeneralRe: Updating Primary Key Pin
PIEBALDconsult6-Nov-07 4:05
mvePIEBALDconsult6-Nov-07 4:05 
GeneralRe: Updating Primary Key Pin
serene joey11-Nov-07 20:10
serene joey11-Nov-07 20:10 
QuestionHooking Direct Api Pin
danzar5-Nov-07 13:16
danzar5-Nov-07 13:16 
QuestionMaking Project Pin
Sameh96140335-Nov-07 11:30
Sameh96140335-Nov-07 11:30 
AnswerRe: Making Project Pin
Paul Conrad5-Nov-07 15:25
professionalPaul Conrad5-Nov-07 15:25 
QuestionData not stored on pocket pc Pin
karanjsingh5-Nov-07 11:19
karanjsingh5-Nov-07 11:19 
QuestionThreadsafe "for" without lock() Pin
szolDat5-Nov-07 11:05
szolDat5-Nov-07 11:05 
I just had an idea and I'd like your opinion.
When you use "for" cycles you have to use lock if more than one thread is executing that part because they may interfere with each other when incrementing the cycle-variable. You have to use lock():

lock(lockObject) {
for(int i = 0; i<x; i++)
{="" do="" work="" }="" }

my="" solution
first="" i="" use="" thread.name="" to="" name="" my="" threads="" with="" an="" int="" in="" a="" cycle,="" like="" this:

for(int="">threadArray.Length; i++)
{ threadArray[i].Name = i.toString(); }

I have to create an array of integers, with the same number of elements as the threads.

int[] intArray = new int[numOfThreads];

Finally my for looks like this:

for(; intArray[Convert.ToInt32(Thread.CurrentThread.Name)]) < x; Interlocked.Increment(ref intArray[Convert.ToInt32(Thread.CurrentThread.Name)]))
{ //Do work }

This way multiple threads can access a cycle instead of waiting until the running thread exits the lock. What do you think?
AnswerRe: Threadsafe &quot;for&quot; without lock() Pin
Guffa5-Nov-07 12:07
Guffa5-Nov-07 12:07 
AnswerRe: Threadsafe &amp;quot;for&amp;quot; without lock() Pin
szolDat5-Nov-07 12:31
szolDat5-Nov-07 12:31 
GeneralRe: Threadsafe &amp;quot;for&amp;quot; without lock() Pin
PIEBALDconsult5-Nov-07 16:02
mvePIEBALDconsult5-Nov-07 16:02 
AnswerRe: Threadsafe &amp;quot;for&amp;quot; without lock() Pin
Guffa5-Nov-07 20:24
Guffa5-Nov-07 20:24 
GeneralRe: Threadsafe &amp;quot;for&amp;quot; without lock() Pin
szolDat6-Nov-07 21:38
szolDat6-Nov-07 21:38 
AnswerRe: Threadsafe &amp;quot;for&amp;quot; without lock() Pin
Guffa6-Nov-07 22:20
Guffa6-Nov-07 22:20 
Questionunknown problem is visual studio Pin
netJP12L5-Nov-07 10:38
netJP12L5-Nov-07 10:38 
AnswerRe: unknown problem is visual studio Pin
Colin Angus Mackay5-Nov-07 11:00
Colin Angus Mackay5-Nov-07 11:00 
GeneralRe: unknown problem is visual studio Pin
netJP12L6-Nov-07 3:56
netJP12L6-Nov-07 3:56 
GeneralRe: EventArgs Pin
half-life5-Nov-07 10:34
half-life5-Nov-07 10:34 
QuestionHash Encryption Pin
Eli Nurman5-Nov-07 9:15
Eli Nurman5-Nov-07 9:15 
AnswerRe: Hash Encryption Pin
led mike5-Nov-07 9:22
led mike5-Nov-07 9:22 
GeneralRe: Hash Encryption Pin
Anthony Mushrow5-Nov-07 12:25
professionalAnthony Mushrow5-Nov-07 12:25 
AnswerRe: Hash Encryption Pin
dino20945-Nov-07 9:42
dino20945-Nov-07 9:42 
QuestionTouchScreen And Mouse separate. [modified] Pin
anselmo5-Nov-07 9:06
anselmo5-Nov-07 9:06 
QuestionQuery based on GUID in Access DB Pin
Christian Graus5-Nov-07 8:58
protectorChristian Graus5-Nov-07 8:58 
AnswerRe: Query based on GUID in Access DB Pin
pmarfleet5-Nov-07 9:51
pmarfleet5-Nov-07 9:51 

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.