tags:

views:

281

answers:

6

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;
            }
        }
A: 

No non-embedded resources. Everything displays fine on initial load.

Please don't reply to questions with your own answer. Reply to them by hitting 'add comment' underneath their answer.
George Stocker
A: 

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.

JaredPar
+1  A: 

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.

A: 

Nothing fancy going on...

private void ShowPleaseWait() { PleaseWait pleaseWait = new PleaseWait();
pleaseWait.ShowDialog(); }

A: 

I just noticed that I'm calling ShowDialog() which probably doesn't make sense in another thread.

A: 

Yep, that was it.