M
MDB
Hello All,
I have an application with 2 threads. The main thread is the application
and the secondary thread checks for messages every minute and when there are
messages, I display them to the user. The problem is that since I am
opening a form from the second thread, it will lock up both threads if the
user is doing something at the time the message is displayed. Can anyone
point me in the right direction on how I should be doing this?
Here is the code I use to display a message
if(myApp.Classes.Globals.gfrmInstantMessage ==
null){myApp.Classes.Globals.gfrmInstantMessage = new frmInstantMessage();}
myApp.Classes.Globals.gfrmInstantMessage.LoadMessageBox("Messages","No New
Messages","");
myApp.Classes.Globals.gfrmInstantMessage.ShowDialog();
myApp.Classes.Globals.gfrmInstantMessage.BringToFront();
myApp.Classes.Globals.gfrmInstantMessage.Focus();
Application.DoEvents();
LoadMessageBox looks like this inside my gfrmInstantMessage Form:
Public void LoadMessageBox(string strHeader, string strMessage, string
sFrom)
{
txtMessage.WordWrap = true;
this.Text = strHeader;
txtMessage.Text = strMessage.Replace("<br>","\r\n");
if(sFrom != PMMobile.Classes.Globals.gstrDispatchId && sFrom != "")
{
txtMessage.Text = "From:\r\n" + sFrom + "\r\n\r\n" + "Message:\r\n" +
txtMessage.Text;
strFrom = sFrom;
txtMessage.Height = 200;
btnReply.Visible=true;
}
else
{
txtMessage.Height = 248;
btnReply.Visible=false;
}
if(this.Text == "Directions")
{
txtMessage.WordWrap = false;
txtMessage.ScrollBars = ScrollBars.Both;
}
}
Thanks
I have an application with 2 threads. The main thread is the application
and the secondary thread checks for messages every minute and when there are
messages, I display them to the user. The problem is that since I am
opening a form from the second thread, it will lock up both threads if the
user is doing something at the time the message is displayed. Can anyone
point me in the right direction on how I should be doing this?
Here is the code I use to display a message
if(myApp.Classes.Globals.gfrmInstantMessage ==
null){myApp.Classes.Globals.gfrmInstantMessage = new frmInstantMessage();}
myApp.Classes.Globals.gfrmInstantMessage.LoadMessageBox("Messages","No New
Messages","");
myApp.Classes.Globals.gfrmInstantMessage.ShowDialog();
myApp.Classes.Globals.gfrmInstantMessage.BringToFront();
myApp.Classes.Globals.gfrmInstantMessage.Focus();
Application.DoEvents();
LoadMessageBox looks like this inside my gfrmInstantMessage Form:
Public void LoadMessageBox(string strHeader, string strMessage, string
sFrom)
{
txtMessage.WordWrap = true;
this.Text = strHeader;
txtMessage.Text = strMessage.Replace("<br>","\r\n");
if(sFrom != PMMobile.Classes.Globals.gstrDispatchId && sFrom != "")
{
txtMessage.Text = "From:\r\n" + sFrom + "\r\n\r\n" + "Message:\r\n" +
txtMessage.Text;
strFrom = sFrom;
txtMessage.Height = 200;
btnReply.Visible=true;
}
else
{
txtMessage.Height = 248;
btnReply.Visible=false;
}
if(this.Text == "Directions")
{
txtMessage.WordWrap = false;
txtMessage.ScrollBars = ScrollBars.Both;
}
}
Thanks