NewMom2Brandon
asked on
Help Needed to check to see if a message box is already being displayed to the user.
I have code written to create a messagebox as soon as I receive a message containing certain key words. What I need to do is to check to see if the messagebox is still on the screen for the user. If it is then I don't want to pop up another message box again.
Does anyone have any examples or know where I can find out how to do this.
This is the code I do have
private void ReceiveData(Byte [] byteBuffer, int size)
{
string sData = Encoding.ASCII.GetString(b yteBuffer, 0, size);
try
{
if((sData.ToLower().IndexO f("disk") > -1) &&
(sData.ToLower().IndexOf(" failed") > -1))
{
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),s Data);
// Displays the MessageBox.
MessageBox.Show("Failure." , "WARNING!!", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Bu tton1,
MessageBoxOptions.ServiceN otificatio n);
}
else if((sData.ToLower().IndexO f("disk") > -1) &&
(sData.ToLower().IndexOf(" failed.") > -1))
{
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),s Data);
// Displays the MessageBox.
MessageBox.Show("Failure", "WARNING!!", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Bu tton1,
MessageBoxOptions.ServiceN otificatio n);
}
else if((sData.ToLower().IndexO f("disk") > -1) &&
(sData.ToLower().IndexOf(" rebuilding ") > -1) &&
(sData.ToLower().IndexOf(" successful ly") > -1))
{
// post the message in the error log
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),s Data);
}
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.EventLo g.WriteEnt ry(this.To String(),s Data);
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),
"Can't process data" + "::Stopped");
}
}
catch(InvalidCastException e)
{
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),
"InvalidCast Error #" + e.Message);
}
}
Does anyone have any examples or know where I can find out how to do this.
This is the code I do have
private void ReceiveData(Byte [] byteBuffer, int size)
{
string sData = Encoding.ASCII.GetString(b
try
{
if((sData.ToLower().IndexO
(sData.ToLower().IndexOf("
{
System.Diagnostics.EventLo
// Displays the MessageBox.
MessageBox.Show("Failure."
MessageBoxIcon.Error, MessageBoxDefaultButton.Bu
MessageBoxOptions.ServiceN
}
else if((sData.ToLower().IndexO
(sData.ToLower().IndexOf("
{
System.Diagnostics.EventLo
// Displays the MessageBox.
MessageBox.Show("Failure",
MessageBoxIcon.Error, MessageBoxDefaultButton.Bu
MessageBoxOptions.ServiceN
}
else if((sData.ToLower().IndexO
(sData.ToLower().IndexOf("
(sData.ToLower().IndexOf("
{
// post the message in the error log
System.Diagnostics.EventLo
}
else if(sData.ToLower().IndexOf
{
m_stopClient=true;
m_markedForDeletion=true;
}
else
{
// post the message in the error log..to catch what message is
System.Diagnostics.EventLo
System.Diagnostics.EventLo
"Can't process data" + "::Stopped");
}
}
catch(InvalidCastException
{
System.Diagnostics.EventLo
"InvalidCast Error #" + e.Message);
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
btw, thats psuedo code, not working syntax, just for the ease of showing you how to do it.
ASKER
hmmm 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.InteropServ ices;
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 QTIEventListenerOCS;
namespace QTIEventListenerOCS
{
/// <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=nul l;
private bool m_markedForDeletion=false;
private bool IsDisplayed=false;
/// <Summary>Client Socket Listener Constructor.</Summary>
/// <param name="clientSocket"></para m>
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(SocketListener ThreadStar t));
m_clientListenerThread.Sta rt();
}
}
/// <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(byt eBuffer);
ReceiveData(byteBuffer, size);
}
catch (SocketException se)
{
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),
"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.Joi n(1000);
/// <Remarks> If still alive; Get rid of the thread.</Remarks>
if (m_clientListenerThread.Is Alive)
{
m_clientListenerThread.Abo rt();
}
m_clientListenerThread=nul l;
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(b yteBuffer, 0, size);
// bool IsDisplayed = false;
try
{
if (IsDisplayed == false)
{
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),s Data);
// Displays the MessageBox.
MessageBox.Show(" Disk Failure. Call xxxxxx", "WARNING!!", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Bu tton1,
MessageBoxOptions.ServiceN otificatio n);
}
else if (IsDisplayed == true)
{
System.Diagnostics.EventLo g.WriteEnt ry(this.To String()," Messagebox already posted");
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),s Data);
}
else
System.Diagnostics.EventLo g.WriteEnt ry(this.To String()," Messagebox check didn't work");
}
catch(InvalidCastException e)
{
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),
"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(b yteBuffer, 0, size);
try
{
if((sData.ToLower().IndexO f("disk") > -1) &&
(sData.ToLower().IndexOf(" failed") > -1))
{
MsgBxDisplayed(byteBuffer, size);
}
else if((sData.ToLower().IndexO f("disk") > -1) &&
(sData.ToLower().IndexOf(" failed.") > -1))
{
MsgBxDisplayed(byteBuffer, size);
}
else if((sData.ToLower().IndexO f("disk") > -1) &&
(sData.ToLower().IndexOf(" rebuilding ") > -1) &&
(sData.ToLower().IndexOf(" successful ly") > -1))
{
// post the message in the error log
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),s Data);
}
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.EventLo g.WriteEnt ry(this.To String(),s Data);
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),
"Can't process data" + "::Stopped");
}
}
catch(InvalidCastException e)
{
System.Diagnostics.EventLo g.WriteEnt ry(this.To String(),
"InvalidCast Error #" + e.Message);
}
}
}
}
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.ServiceProcess;
using System.Runtime.InteropServ
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 QTIEventListenerOCS;
namespace QTIEventListenerOCS
{
/// <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=nul
private bool m_markedForDeletion=false;
private bool IsDisplayed=false;
/// <Summary>Client Socket Listener Constructor.</Summary>
/// <param name="clientSocket"></para
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(SocketListener
m_clientListenerThread.Sta
}
}
/// <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(byt
ReceiveData(byteBuffer, size);
}
catch (SocketException se)
{
System.Diagnostics.EventLo
"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.Joi
/// <Remarks> If still alive; Get rid of the thread.</Remarks>
if (m_clientListenerThread.Is
{
m_clientListenerThread.Abo
}
m_clientListenerThread=nul
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(b
// bool IsDisplayed = false;
try
{
if (IsDisplayed == false)
{
System.Diagnostics.EventLo
// Displays the MessageBox.
MessageBox.Show(" Disk Failure. Call xxxxxx", "WARNING!!", MessageBoxButtons.OK,
MessageBoxIcon.Error, MessageBoxDefaultButton.Bu
MessageBoxOptions.ServiceN
}
else if (IsDisplayed == true)
{
System.Diagnostics.EventLo
System.Diagnostics.EventLo
}
else
System.Diagnostics.EventLo
}
catch(InvalidCastException
{
System.Diagnostics.EventLo
"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(b
try
{
if((sData.ToLower().IndexO
(sData.ToLower().IndexOf("
{
MsgBxDisplayed(byteBuffer,
}
else if((sData.ToLower().IndexO
(sData.ToLower().IndexOf("
{
MsgBxDisplayed(byteBuffer,
}
else if((sData.ToLower().IndexO
(sData.ToLower().IndexOf("
(sData.ToLower().IndexOf("
{
// post the message in the error log
System.Diagnostics.EventLo
}
else if(sData.ToLower().IndexOf
{
m_stopClient=true;
m_markedForDeletion=true;
}
else
{
// post the message in the error log..to catch what message is
System.Diagnostics.EventLo
System.Diagnostics.EventLo
"Can't process data" + "::Stopped");
}
}
catch(InvalidCastException
{
System.Diagnostics.EventLo
"InvalidCast Error #" + e.Message);
}
}
}
}