N
NvrBst
class Program {
static Class1 test = new Class1();
static void Main(string[] args) {
new Thread(() => test.StartWork()).Start();
test.Dispose();
Thread.Sleep(1000);
}
}
class Class1 {
private ReaderWriterLockSlim myStringLock = new
ReaderWriterLockSlim();
private int _cthread;
private volatile bool _fDispose;
public void StartWork() {
Thread.Sleep(200);
_cthread = 2;
ThreadPool.QueueUserWorkItem(new WaitCallback(test));
ThreadPool.QueueUserWorkItem(new WaitCallback(test));
}
public void test(Object nullState) {
myStringLock.EnterWriteLock();
foreach(string A in new string[] { "hello", "goodbye" })
Console.WriteLine(A);
myStringLock.ExitWriteLock();
if(Interlocked.Decrement(ref _cthread) == 0 && _fDispose)
Dispose(true);
}
private int disposed = 0;
public void Dispose() {
_fDispose = true;
if(_cthread == 0) Dispose(true);
}
protected virtual void Dispose(bool disposing)
{ if(Interlocked.Exchange(ref disposed, 1) == 0) if(disposing)
myStringLock.Dispose(); }
}
Object Disposed exception at "myStringLock.EnterWriteLock();", I've
only added a "Thread.Sleep(200);" to illustrate.
I do appologize if I hurt you. I think I might of been missreading
your tone, since you seem to be all over the place. One moment you
seem to be in a mud pit with your "can't admit when your wrong,
complete newbie in the field, etc, etc" just to name a few, then
others you seem to be civil. Either way you do have a "my crap don't
stink, but yours do" feel which doesn't sit well with me.
NB
static Class1 test = new Class1();
static void Main(string[] args) {
new Thread(() => test.StartWork()).Start();
test.Dispose();
Thread.Sleep(1000);
}
}
class Class1 {
private ReaderWriterLockSlim myStringLock = new
ReaderWriterLockSlim();
private int _cthread;
private volatile bool _fDispose;
public void StartWork() {
Thread.Sleep(200);
_cthread = 2;
ThreadPool.QueueUserWorkItem(new WaitCallback(test));
ThreadPool.QueueUserWorkItem(new WaitCallback(test));
}
public void test(Object nullState) {
myStringLock.EnterWriteLock();
foreach(string A in new string[] { "hello", "goodbye" })
Console.WriteLine(A);
myStringLock.ExitWriteLock();
if(Interlocked.Decrement(ref _cthread) == 0 && _fDispose)
Dispose(true);
}
private int disposed = 0;
public void Dispose() {
_fDispose = true;
if(_cthread == 0) Dispose(true);
}
protected virtual void Dispose(bool disposing)
{ if(Interlocked.Exchange(ref disposed, 1) == 0) if(disposing)
myStringLock.Dispose(); }
}
Object Disposed exception at "myStringLock.EnterWriteLock();", I've
only added a "Thread.Sleep(200);" to illustrate.
I do appologize if I hurt you. I think I might of been missreading
your tone, since you seem to be all over the place. One moment you
seem to be in a mud pit with your "can't admit when your wrong,
complete newbie in the field, etc, etc" just to name a few, then
others you seem to be civil. Either way you do have a "my crap don't
stink, but yours do" feel which doesn't sit well with me.
NB