i am not really sure what the hell mutex is but the only way
to make
sure that the threads do not use a shared resource at the
same time is:
The complicated one:
Monitor.Enter(yourFileHandle)
//do the code to write to the file
Monitor.Exit(yourFileHandle)
The easy one:
lock(FileInfo file = new FileInfo(filePath))
{
//your code here
}
and then there is the reader/writer lock which is a low
level
implementation, for which I have heard pretty bad output so
I cannot
comment.
Anyway, all that it means is that while one thread is doing
something
in the between monitor.enter/exit or the lock statement's
brakets no
other thread can go in and do anything. For instance:
ArrayList arrayList = new ArrayList();
lock(arrayList)
{
arrayList.Add("Marty is cool");
arrayList.Remove(0);
}
As soon as a thread enters this array list no other tread
can enter
that code.
Umm, and of course this is from the top of my head so head
on to the
nearest search engine and look for lock statement, and
monitor class
.net
Marty
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "C-Sharp (C#)" group.
To post to this group, send email to C_Sharp googlegroups.com
To unsubscribe from this group, send email to
C_Sharp-unsubscribe googlegroups.com
For more options, visit this group at http://groups.
google.com/group/C_Sharp
-~----------~----~----~----~------~----~------~--~---
|