Can't initialize .Text property in constructor

  • Thread starter Thread starter norvinl
  • Start date Start date
N

norvinl

Hi,

I have a textbox on a form. When I assign a string to the .Text
property while in my form's constructor, the program just hangs
indefinitely.
Alternatively, if I assign the string to the form's .Text property, it
works fine.

this code hangs (never returns from 3rd line):

public frmSubSystemInterface()
{
InitializeComponent();

if ( CDLIsConnected(9) == 1 ) // external dll call
txtMessage.Text = "XRY CONNECTED";
}

this code works fine:

public frmSubSystemInterface()
{
InitializeComponent();

if ( CDLIsConnected(9) == 1 ) // external dll call
this.Text = "XRY CONNECTED";
}

Any ideas?
 
Your two examples are doing two different things.

The first one attempts to set the Text property of a TexBox (txtMessage).

The second one attempts to set the Text property of the Form class itself
(this).
Hope this helps.
Peter
 
P.S.
Try this:
public frmSubSystemInterface()
{
InitializeComponent();
try{
if ( CDLIsConnected(9) == 1 ) // external dll call
txtMessage.Text = "XRY CONNECTED";
}
catch(Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message+ex.StackTrace);
}
}


-- and put a breakpoint on the "System.Diagnostics.... line.
 
Back
Top