Click here to Skip to main content
15,891,431 members
Home / Discussions / C#
   

C#

 
AnswerRe: Read text file after uploaded Pin
Christian Graus20-Jan-07 10:22
protectorChristian Graus20-Jan-07 10:22 
GeneralRe: Read text file after uploaded Pin
ALAQUNAIBI20-Jan-07 19:52
ALAQUNAIBI20-Jan-07 19:52 
GeneralRe: Read text file after uploaded Pin
Christian Graus20-Jan-07 21:43
protectorChristian Graus20-Jan-07 21:43 
QuestionRead-Write thread synchronization Pin
Den2Fly20-Jan-07 1:11
Den2Fly20-Jan-07 1:11 
AnswerRe: Read-Write thread synchronization Pin
Luc Pattyn20-Jan-07 1:38
sitebuilderLuc Pattyn20-Jan-07 1:38 
GeneralRe: Read-Write thread synchronization Pin
Den2Fly20-Jan-07 3:54
Den2Fly20-Jan-07 3:54 
GeneralRe: Read-Write thread synchronization Pin
Luc Pattyn20-Jan-07 4:00
sitebuilderLuc Pattyn20-Jan-07 4:00 
GeneralRe: Read-Write thread synchronization Pin
Den2Fly20-Jan-07 4:37
Den2Fly20-Jan-07 4:37 
Sample:

Here I have a collection class that I want to be thread safe for reading from and manipulation (Not also in the case of iterations). It is assumed any number of threads may enter any of the methods or indexers at the same time. I think for reading from indexers there is no need for a lock, even if there is a chance for more than one thread to enter the indexers, and/or at the same time to one of the Add, Remove, Clear methods. Is it correct? (sorry I don't know how to format code snippets in the post)


internal class MyThreadSafeCollection : System.Collections.Specialized.NameObjectCollectionBase
{
const int readLockTimeout = 100;
const int writeLockTImeout = 100;
private ReaderWriterLock rwLock = new ReaderWriterLock();

public MyThreadSafeCollection()
{
}
public object this[int index]
{
get
{
rwLock.AcquireReaderLock(readLockTimeout); // IS THIS REQUIRED ??
try
{
return BaseGet(index);
}
finally
{
rwLock.ReleaseReaderLock();
}
}
}
public SocketClientData this[string id]
{
get
{
rwLock.AcquireReaderLock(readLockTimeout); // IS THIS REQUIRED ??
try
{
return BaseGet(id);
}
finally
{
rwLock.ReleaseReaderLock();
}
}
}
public void Add(string id, SocketClientData client)
{
rwLock.AcquireWriterLock(writeLockTImeout); // I Know it is required. (isn't it?)
try
{
BaseAdd(id, client);
}
finally
{
rwLock.ReleaseWriterLock();
}
}
public void Remove(string id)
{
rwLock.AcquireWriterLock(writeLockTImeout); // I Know it is required. (isn't it?)
try
{
BaseRemove(id);
}
finally
{
rwLock.ReleaseWriterLock();
}
}
public void Clear()
{
rwLock.AcquireWriterLock(writeLockTImeout); // I Know it is required. (isn't it?)
try
{
BaseClear();
}
finally
{
rwLock.ReleaseWriterLock();
}
}




---
"Art happens when you least expect it."

GeneralRe: Read-Write thread synchronization Pin
Luc Pattyn20-Jan-07 5:15
sitebuilderLuc Pattyn20-Jan-07 5:15 
GeneralRe: Read-Write thread synchronization Pin
Den2Fly20-Jan-07 5:28
Den2Fly20-Jan-07 5:28 
Questionhow to access html document in C# appliication Pin
imshimshal19-Jan-07 23:00
imshimshal19-Jan-07 23:00 
AnswerRe: how to access html document in C# appliication Pin
Christian Graus19-Jan-07 23:14
protectorChristian Graus19-Jan-07 23:14 
QuestionHow can I make my C# .NET work on other computers Pin
Par Witch19-Jan-07 21:39
Par Witch19-Jan-07 21:39 
AnswerRe: How can I make my C# .NET work on other computers Pin
Christian Graus19-Jan-07 22:33
protectorChristian Graus19-Jan-07 22:33 
AnswerRe: How can I make my C# .NET work on other computers Pin
Mircea Puiu19-Jan-07 22:34
Mircea Puiu19-Jan-07 22:34 
GeneralRe: How can I make my C# .NET work on other computers Pin
Par Witch20-Jan-07 4:23
Par Witch20-Jan-07 4:23 
GeneralRe: How can I make my C# .NET work on other computers Pin
Mircea Puiu21-Jan-07 21:00
Mircea Puiu21-Jan-07 21:00 
GeneralRe: How can I make my C# .NET work on other computers Pin
Par Witch22-Jan-07 3:46
Par Witch22-Jan-07 3:46 
GeneralRe: How can I make my C# .NET work on other computers Pin
Mircea Puiu22-Jan-07 4:10
Mircea Puiu22-Jan-07 4:10 
QuestionReturning 3 value from function Pin
dabuskol19-Jan-07 20:06
dabuskol19-Jan-07 20:06 
AnswerRe: Returning 3 value from function Pin
Bassam Saoud19-Jan-07 21:35
Bassam Saoud19-Jan-07 21:35 
AnswerRe: Returning 3 value from function Pin
Stefan Troschuetz19-Jan-07 21:56
Stefan Troschuetz19-Jan-07 21:56 
GeneralRe: Returning 3 value from function Pin
Christian Graus19-Jan-07 22:35
protectorChristian Graus19-Jan-07 22:35 
GeneralRe: Returning 3 value from function Pin
Stefan Troschuetz19-Jan-07 22:49
Stefan Troschuetz19-Jan-07 22:49 
AnswerRe: Returning 3 value from function Pin
Christian Graus19-Jan-07 22:28
protectorChristian Graus19-Jan-07 22:28 

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.