I have made a WPF application which has a button to move some files attached to the column cells from one column to another column. The moment when I press the button it shows a nice animation and moves all files to the next column's cells.
But my real problem is once I give my function color_check(), my application is getting stuck. I really don't know why. Is there any help I can get out for this?
Code:
private void button3_Click(object sender, EventArgs e) { Hide(); bool done = false; ThreadPool.QueueUserWorkItem((x) => { using (var splashForm = new Form4()) { splashForm.Show(); while (!done) Application.DoEvents(); splashForm.Close(); } }); move(); //file moving function //color_check(); if i give this fn, my form stucks and comes to live after 10 - 20 sec done = true; MessageBox.Show("TEST FINISHED"); Show(); } public void color_check() //this is my problem making fn { dataGridView1.Refresh(); string strVal = ini.ReadValue("Action", "Doc-Controller"); bool authenticated = true; if (authenticated == UserInCustomRole(strVal)) { foreach (DataGridViewRow row in dataGridView1.Rows) { // Application.DoEvents(); string fName1 = System.IO.Path.GetFileNameWithoutExtension(row.Cells[3].Value.ToString()); string fName2 = System.IO.Path.GetFileNameWithoutExtension(row.Cells[4].Value.ToString()); if (!string.IsNullOrEmpty(fName1) && !string.IsNullOrEmpty(fName2)) { var f1 = GetValue(fName1.ToCharArray()[fName1.Length - 2]) * 16 + GetValue(fName1.ToCharArray()[fName1.Length - 1]); var f2 = GetValue(fName2.ToCharArray()[fName2.Length - 2]) * 16 + GetValue(fName2.ToCharArray()[fName2.Length - 1]); //if (System.IO.Path.GetFileName(fName1) != System.IO.Path.GetFileName(fName2)) if (f1 > f2) { //MessageBox.Show(fName1); DataGridViewCellStyle style = new DataGridViewCellStyle(); style.BackColor = Color.Yellow; row.Cells[3].Style = style; } else if (f2 > f1) { //MessageBox.Show(fName1); DataGridViewCellStyle style = new DataGridViewCellStyle(); style.BackColor = Color.Yellow; row.Cells[4].Style = style; } if (f1 == f2) { DataGridViewCellStyle style = new DataGridViewCellStyle(); style.BackColor = Color.Plum; row.Cells[4].Style = style; row.Cells[3].Style = style; } } } }
BackgroundWorkerthread for thecolor_check()method?color_checkto a task and run it or make it async, but remember that if you have to change something in the GUI you will have to Invoke the controls you wanna change