Click here to Skip to main content
15,900,461 members
Home / Discussions / C#
   

C#

 
GeneralRe: create public variables at run time Pin
Jassim Rahma9-Apr-10 11:52
Jassim Rahma9-Apr-10 11:52 
GeneralRe: create public variables at run time Pin
Not Active9-Apr-10 14:04
mentorNot Active9-Apr-10 14:04 
AnswerRe: create public variables at run time Pin
NavnathKale10-Apr-10 0:56
NavnathKale10-Apr-10 0:56 
GeneralRe: create public variables at run time Pin
Jassim Rahma10-Apr-10 12:02
Jassim Rahma10-Apr-10 12:02 
GeneralRe: create public variables at run time Pin
NavnathKale10-Apr-10 21:49
NavnathKale10-Apr-10 21:49 
Questionkeep one sqlconnection alive Pin
Jassim Rahma8-Apr-10 13:31
Jassim Rahma8-Apr-10 13:31 
AnswerRe: keep one sqlconnection alive Pin
PIEBALDconsult8-Apr-10 13:59
mvePIEBALDconsult8-Apr-10 13:59 
GeneralRe: keep one sqlconnection alive Pin
Jassim Rahma8-Apr-10 14:14
Jassim Rahma8-Apr-10 14:14 
GeneralRe: keep one sqlconnection alive Pin
PIEBALDconsult8-Apr-10 17:11
mvePIEBALDconsult8-Apr-10 17:11 
GeneralRe: keep one sqlconnection alive Pin
Dave Kreskowiak8-Apr-10 17:48
mveDave Kreskowiak8-Apr-10 17:48 
AnswerRe: keep one sqlconnection alive Pin
Not Active8-Apr-10 14:13
mentorNot Active8-Apr-10 14:13 
AnswerRe: keep one sqlconnection alive Pin
N a v a n e e t h8-Apr-10 16:21
N a v a n e e t h8-Apr-10 16:21 
Questionmake a default printer Pin
Jassim Rahma8-Apr-10 13:30
Jassim Rahma8-Apr-10 13:30 
AnswerRe: make a default printer Pin
loyal ginger9-Apr-10 7:02
loyal ginger9-Apr-10 7:02 
QuestionText overlay on webcam streaming videos PinPopular
bdb388658-Apr-10 12:46
bdb388658-Apr-10 12:46 
QuestionInput type ="image" in c# Pin
tedyboy98-Apr-10 11:15
tedyboy98-Apr-10 11:15 
AnswerRe: Input type ="image" in c# Pin
Arun Jacob8-Apr-10 19:07
Arun Jacob8-Apr-10 19:07 
GeneralRe: Input type ="image" in c# Pin
tedyboy98-Apr-10 21:07
tedyboy98-Apr-10 21:07 
QuestionManualResetEvent set()/waitOne() Pin
igalep1328-Apr-10 9:17
igalep1328-Apr-10 9:17 
AnswerRe: ManualResetEvent set()/waitOne() Pin
Luc Pattyn8-Apr-10 9:26
sitebuilderLuc Pattyn8-Apr-10 9:26 
AnswerRe: ManualResetEvent set()/waitOne() Pin
supercat98-Apr-10 9:44
supercat98-Apr-10 9:44 
GeneralRe: ManualResetEvent set()/waitOne() Pin
igalep1328-Apr-10 10:09
igalep1328-Apr-10 10:09 
AnswerRe: ManualResetEvent set()/waitOne() Pin
igalep1328-Apr-10 10:52
igalep1328-Apr-10 10:52 
i wote next code

class SynchronizedMailBox : MailBox
    {
        private static ManualResetEvent mre = new ManualResetEvent(false);//signale for blocking till first set() call
        private static Mutex mainMutex = new Mutex(false);

        public override void Write(Message msg)
        {
            mainMutex.WaitOne();//lock array Message for writing into it

                if (IsEmpty())//if array message is still empty, release all waiting read thread (if any) 
                    mre.Set();

                base.Write(msg);

            mainMutex.ReleaseMutex();//unLock array Message after writing into it
        }

        public override Message Read()
        {
            mainMutex.WaitOne();//lock array Message for reading from it

                mre.WaitOne();//if first thread is for reading, and array message is empty, wait here
            
                Message ms = base.Read();

                if (IsEmpty())//if after reading no messages has left, reset(), for next thread to be blocked before reading
                    mre.Reset();

            mainMutex.ReleaseMutex();//unLock array Message after reading from it

            return ms;
        }
    }


my question is, what will be happen when those lines will be executed
if (IsEmpty())//if array message is still empty, release all waiting read thread (if any)
                   mre.Set();

and there are blocked thread/s on WaitOne() in read method.
the fact that write method is still under the mutex will prevent from unblocked reading thread/s to continue running ?

one more question is about if(isEmpty()) inside read method ,
do i need one more mutex to close the "if" or the main mutex which "close" the whole method is enough ?

tanks
GeneralRe: ManualResetEvent set()/waitOne() Pin
igalep1329-Apr-10 0:37
igalep1329-Apr-10 0:37 
GeneralRe: ManualResetEvent set()/waitOne() Pin
supercat910-Apr-10 13:21
supercat910-Apr-10 13:21 

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.