S
Steve Ricketts
I'm simply trying to open a form from another form and as soon as the new
form is shown, it locks up with a not responding message in the title bar.
However, I'm able to walk through the code behind the form and that still
works.
The scenario is that a learner is logging on to the application with a USB
wireless remote. The form I'm trying to open is just a template so they can
see what buttons correspond to what letters and show them what they've
entered (like texting on a phone).
Here is the basic flow in form (frmClient):
private frmTexting frmTexting1;
....
Later in the same frmClient:
private void onComm(object sender, SerialDataReceivedEventArgs e)
{
....
GotCommInput(buffer);
....
}
private void GotCommInput(byte[] buffer)
{
....
frmTexting1 = new frmTexting(); // Show is in the initialization of
frmTexting...
frmTexting1.Show(); // I've tried adding show
here as well
}
In debug mode, I can walk through the process from when the serial port data
is received, calls GotCommInput, creates the new frmTexting1, initializes
all the variables in frmTexting1, and as soon as it hits either
frmTexting.Show or frmTexting.visible=true (I tried both), the form opens
but nothing is on it. I can continue to walk the debugger through each
line, back to onComm, and out... call stack is empty. But the form is still
white and if you click on it you get the "not responding" message added to
the title bar.
The really odd part (at least to me) is that I can send another message
through the serial port and, using the debugger, I can step through each
line of code from onComm, to GotCommInput, to the code in frmTexting1...
which is the code behind the form that's not responding! So, what scenarios
could cause the form not respond but the code work?
Thanks for any ideas or direction,
Steve
PS. I didn't know if the real code would help, but it's so long I just cut
out the parts that don't come into play in this scenario and included it
below.
private void onComm(object sender, SerialDataReceivedEventArgs e)
{
int i = 0;
int bytes = 0;
int cCmd = 0;
int cNum = 0;
int cUnit = 0;
byte[] cData;
byte[] buffer;
// Read the data from the port and store it in our buffer
while (comport.BytesToRead > 0 || USBbuffer.Length > 0)
{
while (comport.BytesToRead > 0)
{
bytes = comport.BytesToRead;
buffer = new byte[bytes];
comport.Read(buffer, 0, bytes);
USBbuffer = CADEmain.concatArray(USBbuffer, buffer);
}
cCmd = USBbuffer[BT_CMD];
cUnit = USBbuffer[BT_UNIT] * 256;
cUnit = USBbuffer[BT_UNIT + 1] + 1;
switch (cCmd)
{
case BT_KEY: //key
cData = new byte[2];
cData[0] = USBbuffer[BT_DATA];
cData[1] = USBbuffer[BT_DATA + 1];
GotCommInput(cCmd, cUnit, cData,
USBbuffer[BT_VERSION], USBbuffer[BT_BATTERY]);
if (USBbuffer.Length == PK_LEN)
{
USBbuffer = new byte[0];
}
else {
buffer = new byte[USBbuffer.Length - PK_LEN];
Array.Copy(USBbuffer, PK_LEN, buffer, 0,
USBbuffer.Length - PK_LEN);
USBbuffer = new byte[buffer.Length];
Array.Copy(buffer, USBbuffer, buffer.Length);
}
break;
}
}
}
public void GotCommInput(int cCmd, int comUnit, byte[] cData, int
rmVersion, int cBattVolts)
{
int numPress = 0;
int CallIndex = 0;
numPress = cData[0] * 256;
numPress = numPress + cData[1];
CallIndex = thisRemote(comUnit.ToString());
if (CallIndex == -1 && remoteProperties != 15)
{
//Don't know who this is, use it to log on
if (dlClient.useTexting && !KeypadSelection)
{ //Use remote texting to logon
if (usersLogonRemoteId == "")
{ //Haven't established which remote
usersLogonRemoteId = comUnit.ToString();
frmTexting1 = new frmTexting();
// Bad thing happens here...
return;
}
if (comUnit.ToString() == usersLogonRemoteId )
{ //If logon remote, pass keys to texting
frmTexting1.btn_Click(numPress);
return;
}
}
}
Code in frmTexting
namespace dlTextCS
{
public partial class frmTexting : Form
{
public Control[] btn = new Button[14];
private int lastValue = 0;
private int keyPointer = 0;
private char DLMT = (char)1;
private string charSelection = "";
private string charHere = "";
public frmTexting()
{
InitializeComponent();
Form_Load();
}
private void Form_Load()
{
int i = 0;
int x = 0;
keyTimer.Tick += new EventHandler(keyTimer_Tick);
for (i = 0; i < this.Controls.Count; i++)
{
if (this.Controls.GetType().ToString() ==
"System.Windows.Forms.Button")
{
x = Convert.ToInt16(this.Controls.Tag);
btn[x] = (Button)this.Controls;
}
}
btn[11].Text = "num";
this.Show(); // tried visible = true but
this is where things go bad
}
public string btn_Click(int Index)
{
int i = 0;
string s = "";
if (btn[11].Text == "alpha") keyTimer.Enabled = false;
if (Index == 15 || Index == 0 || Index == 14) return "";
switch (Index)
{
case 11: //Alpha/Numeric toggle;
if (btn[11].Text == "alpha")
{
for (i = 1; i < 11; i++)
{
btn.Text = btn.Tag.ToString();
if (btn.Text == "")
{
btn.Visible = false;
}
else
{
btn.Visible = true;
}
}
btn[11].Text = "num";
}
else
{
for (i = 1; i < 11; i++)
{
btn.Visible = true;
btn.Tag = btn.Text;
btn.Text = i.ToString();
}
btn[10].Text = "0";
btn[11].Text = "alpha";
}
break;
case 12: //Back;
if (labID.Text == "_") return "";
labID.Text = labID.Text.Replace("_", "");
labID.Text = CADEmain.Left(labID.Text,
labID.Text.Length - 1) + "_";
break;
case 13: //Enter;
charSelection = labID.Text.Replace("_", "");
break;
default:
if (lastValue != Index)
{
s = labID.Text;
s = s.Replace("_", "");
labID.Invoke((MethodInvoker)delegate { labID.Text =
s + "_"; });
keyTimer.Enabled = false;
keyTimer.Stop();
}
if (keyTimer.Enabled)
{
charSelection = btn[Index].Text;
keyTimer.Enabled = false;
keyTimer.Stop();
keyPointer = keyPointer + 1;
if (keyPointer > charSelection.Length) keyPointer =
1;
charHere = CADEmain.Mid(charSelection, keyPointer,
1);
if (labID.Text.Length > 0)
{
labID.Text = CADEmain.Left(labID.Text,
labID.Text.Length - 1) + charHere.ToUpper();
}
}
else
{
lastValue = Index;
keyPointer = 1;
if (btn[11].Text == "alpha")
{
labID.Text = labID.Text.Replace("_", "");
labID.Text = labID.Text +
(CADEmain.Mid(btn[Index].Text.ToUpper(), 1, 1)) + "_";
}
else
{
if (Index < 11 && Index != 0)
{
labID.Text = CADEmain.Left(labID.Text,
labID.Text.Length - 1) + (CADEmain.Mid(btn[Index].Text.ToUpper(), 1, 1));
}
}
}
keyTimer.Enabled = true;
keyTimer.Start();
break;
}
return labID.Text;
}
private void keyTimer_Tick(object sender, EventArgs e)
{
keyTimer.Enabled = false;
keyTimer.Stop();
if (btn[11].Text == "num")
{
labID.Text = labID.Text + "_";
}
}
}
}
form is shown, it locks up with a not responding message in the title bar.
However, I'm able to walk through the code behind the form and that still
works.
The scenario is that a learner is logging on to the application with a USB
wireless remote. The form I'm trying to open is just a template so they can
see what buttons correspond to what letters and show them what they've
entered (like texting on a phone).
Here is the basic flow in form (frmClient):
private frmTexting frmTexting1;
....
Later in the same frmClient:
private void onComm(object sender, SerialDataReceivedEventArgs e)
{
....
GotCommInput(buffer);
....
}
private void GotCommInput(byte[] buffer)
{
....
frmTexting1 = new frmTexting(); // Show is in the initialization of
frmTexting...
frmTexting1.Show(); // I've tried adding show
here as well
}
In debug mode, I can walk through the process from when the serial port data
is received, calls GotCommInput, creates the new frmTexting1, initializes
all the variables in frmTexting1, and as soon as it hits either
frmTexting.Show or frmTexting.visible=true (I tried both), the form opens
but nothing is on it. I can continue to walk the debugger through each
line, back to onComm, and out... call stack is empty. But the form is still
white and if you click on it you get the "not responding" message added to
the title bar.
The really odd part (at least to me) is that I can send another message
through the serial port and, using the debugger, I can step through each
line of code from onComm, to GotCommInput, to the code in frmTexting1...
which is the code behind the form that's not responding! So, what scenarios
could cause the form not respond but the code work?
Thanks for any ideas or direction,
Steve
PS. I didn't know if the real code would help, but it's so long I just cut
out the parts that don't come into play in this scenario and included it
below.
private void onComm(object sender, SerialDataReceivedEventArgs e)
{
int i = 0;
int bytes = 0;
int cCmd = 0;
int cNum = 0;
int cUnit = 0;
byte[] cData;
byte[] buffer;
// Read the data from the port and store it in our buffer
while (comport.BytesToRead > 0 || USBbuffer.Length > 0)
{
while (comport.BytesToRead > 0)
{
bytes = comport.BytesToRead;
buffer = new byte[bytes];
comport.Read(buffer, 0, bytes);
USBbuffer = CADEmain.concatArray(USBbuffer, buffer);
}
cCmd = USBbuffer[BT_CMD];
cUnit = USBbuffer[BT_UNIT] * 256;
cUnit = USBbuffer[BT_UNIT + 1] + 1;
switch (cCmd)
{
case BT_KEY: //key
cData = new byte[2];
cData[0] = USBbuffer[BT_DATA];
cData[1] = USBbuffer[BT_DATA + 1];
GotCommInput(cCmd, cUnit, cData,
USBbuffer[BT_VERSION], USBbuffer[BT_BATTERY]);
if (USBbuffer.Length == PK_LEN)
{
USBbuffer = new byte[0];
}
else {
buffer = new byte[USBbuffer.Length - PK_LEN];
Array.Copy(USBbuffer, PK_LEN, buffer, 0,
USBbuffer.Length - PK_LEN);
USBbuffer = new byte[buffer.Length];
Array.Copy(buffer, USBbuffer, buffer.Length);
}
break;
}
}
}
public void GotCommInput(int cCmd, int comUnit, byte[] cData, int
rmVersion, int cBattVolts)
{
int numPress = 0;
int CallIndex = 0;
numPress = cData[0] * 256;
numPress = numPress + cData[1];
CallIndex = thisRemote(comUnit.ToString());
if (CallIndex == -1 && remoteProperties != 15)
{
//Don't know who this is, use it to log on
if (dlClient.useTexting && !KeypadSelection)
{ //Use remote texting to logon
if (usersLogonRemoteId == "")
{ //Haven't established which remote
usersLogonRemoteId = comUnit.ToString();
frmTexting1 = new frmTexting();
// Bad thing happens here...
return;
}
if (comUnit.ToString() == usersLogonRemoteId )
{ //If logon remote, pass keys to texting
frmTexting1.btn_Click(numPress);
return;
}
}
}
Code in frmTexting
namespace dlTextCS
{
public partial class frmTexting : Form
{
public Control[] btn = new Button[14];
private int lastValue = 0;
private int keyPointer = 0;
private char DLMT = (char)1;
private string charSelection = "";
private string charHere = "";
public frmTexting()
{
InitializeComponent();
Form_Load();
}
private void Form_Load()
{
int i = 0;
int x = 0;
keyTimer.Tick += new EventHandler(keyTimer_Tick);
for (i = 0; i < this.Controls.Count; i++)
{
if (this.Controls.GetType().ToString() ==
"System.Windows.Forms.Button")
{
x = Convert.ToInt16(this.Controls.Tag);
btn[x] = (Button)this.Controls;
}
}
btn[11].Text = "num";
this.Show(); // tried visible = true but
this is where things go bad
}
public string btn_Click(int Index)
{
int i = 0;
string s = "";
if (btn[11].Text == "alpha") keyTimer.Enabled = false;
if (Index == 15 || Index == 0 || Index == 14) return "";
switch (Index)
{
case 11: //Alpha/Numeric toggle;
if (btn[11].Text == "alpha")
{
for (i = 1; i < 11; i++)
{
btn.Text = btn.Tag.ToString();
if (btn.Text == "")
{
btn.Visible = false;
}
else
{
btn.Visible = true;
}
}
btn[11].Text = "num";
}
else
{
for (i = 1; i < 11; i++)
{
btn.Visible = true;
btn.Tag = btn.Text;
btn.Text = i.ToString();
}
btn[10].Text = "0";
btn[11].Text = "alpha";
}
break;
case 12: //Back;
if (labID.Text == "_") return "";
labID.Text = labID.Text.Replace("_", "");
labID.Text = CADEmain.Left(labID.Text,
labID.Text.Length - 1) + "_";
break;
case 13: //Enter;
charSelection = labID.Text.Replace("_", "");
break;
default:
if (lastValue != Index)
{
s = labID.Text;
s = s.Replace("_", "");
labID.Invoke((MethodInvoker)delegate { labID.Text =
s + "_"; });
keyTimer.Enabled = false;
keyTimer.Stop();
}
if (keyTimer.Enabled)
{
charSelection = btn[Index].Text;
keyTimer.Enabled = false;
keyTimer.Stop();
keyPointer = keyPointer + 1;
if (keyPointer > charSelection.Length) keyPointer =
1;
charHere = CADEmain.Mid(charSelection, keyPointer,
1);
if (labID.Text.Length > 0)
{
labID.Text = CADEmain.Left(labID.Text,
labID.Text.Length - 1) + charHere.ToUpper();
}
}
else
{
lastValue = Index;
keyPointer = 1;
if (btn[11].Text == "alpha")
{
labID.Text = labID.Text.Replace("_", "");
labID.Text = labID.Text +
(CADEmain.Mid(btn[Index].Text.ToUpper(), 1, 1)) + "_";
}
else
{
if (Index < 11 && Index != 0)
{
labID.Text = CADEmain.Left(labID.Text,
labID.Text.Length - 1) + (CADEmain.Mid(btn[Index].Text.ToUpper(), 1, 1));
}
}
}
keyTimer.Enabled = true;
keyTimer.Start();
break;
}
return labID.Text;
}
private void keyTimer_Tick(object sender, EventArgs e)
{
keyTimer.Enabled = false;
keyTimer.Stop();
if (btn[11].Text == "num")
{
labID.Text = labID.Text + "_";
}
}
}
}