Clint
Clint

Reputation:

.NET winforms application controls turn to red x's

I've deployed a C#.net 2.0 application to a Windows XP SP2 machine and during certain events a lot of the form controls turn to red X's. (Buttons, labels, etc...). I've pasted one of the procedures below that causes the problem. Since I can't reproduce it on the development machine, I can only guess that the problem is either with the threading or painting.

 private void SearchExistingPeople()
        {
            try { if (_dal == null) { _dal = new DataAccessLayer(); } }
            catch (Exception ex) { throw new Exception("Error creating DataAccessLayer: " + ex.Message); }

            Thread oThread = new Thread(ShowPleaseWait);
            oThread.Start();

            try
            {
                PersonDS _dsPerson = _dal.SearchExistingPersons(dtbSearchDOB.Value, txtSearchFName.Text, txtSearchLName.Text, txtSearchSSN.Text, txtSearchAKA.Text, chkDOBSearch.Checked);
                dgvPeople.DataSource = _dsPerson;
                dgvPeople.DataMember = "People";

                dgvPeople.Columns["PersonID"].Visible = false;
            }
            catch (Exception ex)
            { MessageBox.Show("Error in SearchExistingPeople: " + ex.Message); }
            finally
            { 
                if (_dal != null) { _dal = null; }
                oThread.Abort();
                oThread = null;
            }
        }

Upvotes: 2

Views: 2057

Answers (2)

user51886
user51886

Reputation: 332

The red cross is normally drawn by the .NET framework itself when you access a UI control from another thread than the UI thread.

Maybe there is an a cross-thread call inside of ShowPleaseWait or SearchExistingPersons. (Please post the code for those routines.)

The cross is also displayed when a resource is not available.

Upvotes: 1

JaredPar
JaredPar

Reputation: 755269

Shot in the dark. How does ShowPleaseWait work? Does it try and touch any of the controls that are currently displaying? If so this is the source of your problems. It's not legal to use controls from a background thread.

One quick and dirty way to test this out would be to use essentially an empty method instead of ShowPleaseWait.

Upvotes: 0

Related Questions