Help ASAP...messagebox still not working correctly.

I have a messagebox that I only want to pop up if it is not already being displayed on the screen.

My code is still poping up the messagebox even though it is on the screen. What am I doing wrong here. Any suggestions on how to fix this

what am I doing wrong...it is still poping up the box even though it is already displayed

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Runtime.InteropServices;
using System.Net.Sockets;
using System.Threading;
using System.Text;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Web;
using System.Windows.Forms;

using EventListenerOCS;

namespace EventListener
{
   /// <Summary> Summary description for SocketListener.</Summary>
   public class SocketListener
   {
      /// <Remarks> Variables that are accessed by other classes indirectly.</Remarks>
      private Socket m_clientSocket = null;
      private bool m_stopClient=false;
      private Thread m_clientListenerThread=null;
      private bool m_markedForDeletion=false;
      private bool IsDisplayed=false;
      /// <Summary>Client Socket Listener Constructor.</Summary>
      /// <param name="clientSocket"></param>
      public SocketListener(Socket clientSocket)
      {
         m_clientSocket = clientSocket;
      }

      /// <Summary> Client SocketListener Destructor.</Summary>
      ~SocketListener()
      {
         StopSocketListener();
      }

      /// <Summary>  Method that starts SocketListener Thread.</Summary>
      public void StartSocketListener()
      {
         if (m_clientSocket!= null)
         {
            m_clientListenerThread =
               new Thread(new ThreadStart(SocketListenerThreadStart));

            m_clientListenerThread.Start();
         }
      }

      /// <Summary>  Thread method that does the communication to the client.</Summary>
      /// <Remarks> This thread tries to receive data from client.</remarks>
      private void SocketListenerThreadStart()
      {
         int size=0;
         Byte [] byteBuffer = new Byte[1024];

         while (!m_stopClient)
         {
            try
            {
               size = m_clientSocket.Receive(byteBuffer);
               ReceiveData(byteBuffer, size);
            }
            catch (SocketException se)
            {
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),
                  "Socket Error #" + se.ErrorCode + ":: " + se.Message);

               m_stopClient=true;
               m_markedForDeletion=true;
            }
         }
      }

      /// <Summary> Method that stops Client SocketListening Thread.</Summary>
      public void StopSocketListener()
      {
         if (m_clientSocket!= null)
         {
            m_stopClient=true;
            m_clientSocket.Close();

            /// <Remarks>Wait for one second for the the thread to stop.</Remarks>
            m_clientListenerThread.Join(1000);
                   
            /// <Remarks> If still alive; Get rid of the thread.</Remarks>
            if (m_clientListenerThread.IsAlive)
            {
               m_clientListenerThread.Abort();
            }
            m_clientListenerThread=null;
            m_clientSocket=null;
            m_markedForDeletion=true;
         }
      }

      /// <Summary> Method that returns the state of this object</Summary>
      /// <Remarks> i.e. whether this object is marked for deletion or not.<Remarks>
      /// <returns></returns>
      public bool IsMarkedForDeletion()
      {
         return m_markedForDeletion;
      }


      /// <Summary> This method checks to see if the messagebox is displayed
      /// on the XXX already.</Summary>
      /// <param name="byteBuffer"></param>
      /// <param name="size"></param>
      ///
      private void MsgBxDisplayed(Byte [] byteBuffer, int size)
      {
         string sData = Encoding.ASCII.GetString(byteBuffer,0, size);
//         bool IsDisplayed = false;


         try
         {

            if (IsDisplayed == false)
            {
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),sData);
               // Displays the MessageBox.

                  MessageBox.Show(" Disk Failure. Call xxxxxx", "WARNING!!", MessageBoxButtons.OK,
                  MessageBoxIcon.Error, MessageBoxDefaultButton.Button1,
                  MessageBoxOptions.ServiceNotification);
            }

            else if (IsDisplayed == true)
            {
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),"Messagebox already posted");
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),sData);
            }
            else
               System.Diagnostics.EventLog.WriteEntry(this.ToString(),"Messagebox check didn't work");

         }
         catch(InvalidCastException e)
         {
            System.Diagnostics.EventLog.WriteEntry(this.ToString(),
               "InvalidCast Error #" + e.Message);
         }

      }
      /// <Summary> This method reads data sent by a client from the received buffer
      /// It will post the message into the errorlog, pop up the form onto the ocs,
      /// and send a confirmation back to the client</Summary>
      /// <param name="byteBuffer"></param>
      /// <param name="size"></param>
      ///
      private void ReceiveData(Byte [] byteBuffer, int size)
      {
         string sData = Encoding.ASCII.GetString(byteBuffer,0, size);

         try
         {
            if((sData.ToLower().IndexOf("disk") > -1) &&
               (sData.ToLower().IndexOf("failed") > -1))

               {
                    MsgBxDisplayed(byteBuffer, size);
               }

               else if((sData.ToLower().IndexOf("disk") > -1) &&
                  (sData.ToLower().IndexOf("failed.") > -1))
               {

                    MsgBxDisplayed(byteBuffer, size);
               }

               else if((sData.ToLower().IndexOf("disk") > -1) &&
                  (sData.ToLower().IndexOf("rebuilding") > -1) &&
                  (sData.ToLower().IndexOf("successfully") > -1))
               {
                  // post the message in the error log
                  System.Diagnostics.EventLog.WriteEntry(this.ToString(),sData);

               }

               else if(sData.ToLower().IndexOf(null) > -1)
               {

                  m_stopClient=true;
                  m_markedForDeletion=true;

               }

               else
               {
                  // post the message in the error log..to catch what message is
                  System.Diagnostics.EventLog.WriteEntry(this.ToString(),sData);

                  System.Diagnostics.EventLog.WriteEntry(this.ToString(),
                     "Can't process data" + "::Stopped");
               }
         }

         catch(InvalidCastException e)
         {
            System.Diagnostics.EventLog.WriteEntry(this.ToString(),
               "InvalidCast Error #" + e.Message);
         }

      }
     }
}
LVL 2
NewMom2BrandonAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

shankar_msCommented:
IsDisplayed is not set to true at any place...???

Sh
0
NewMom2BrandonAuthor Commented:
I changed it to be true and still had the same thing happen.
0
cookreCommented:
Such use of synchronization variables is prone to failure.  Use a mutex instead.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

NewMom2BrandonAuthor Commented:
I am still having a hard time getting this to work. Even the Mutex
0
NewMom2BrandonAuthor Commented:
Since I am having such a hard time getting this to work. Do know if there is a easy way to just timeout the messagebox instead
0
cookreCommented:

// Show message if it's not already there
{
private bool DidIGetIt;
private Mutex mut = new Mutex(true,"JustForMeRightHere",DidIGetIt);
if (DidIGetIt)
   {
   ... show message
   
   }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.