Inresponsive program during an Active Directory search.
-
Below is some code that validates entries in a datagridview against entries in Active Directory and changes the color of the datagridview cells accordingly. A progressbar indicates how far the process is from finish. If the user then interacts with the form either by dragging one of the datagridview scrollbars or pressing a button, the program becomes unresponsive and the form doesn't refresh any longer until after the process is finished, thereby causing the progressbar to loose its functionality. How can I overcome this glitch? I would also like to implement a cancel button so that the user can cancel the validation process at any moment, but if a button is pressed I experience the problem mentioned above. Any help would be appreciated. Thanx. private void btnCheck_Click(object sender, EventArgs e) { using (DirectoryEntry de = new DirectoryEntry(adPath, adUsername, adPassword)) //)) { de.Username = Environment.UserName; de.AuthenticationType = AuthenticationTypes.Secure; //these are the attributes that will show string[] attribs = new string[] { "displayName", "mail", "userAccountControl" }; for (int x = 0; x < dgvManager.Rows.Count - 1; x++) { ValidateDetails(4, 5, 6, x, de, attribs); //Second in charge ValidateDetails(7, 8, 9, x, de, attribs); //Branch Manager
-
Below is some code that validates entries in a datagridview against entries in Active Directory and changes the color of the datagridview cells accordingly. A progressbar indicates how far the process is from finish. If the user then interacts with the form either by dragging one of the datagridview scrollbars or pressing a button, the program becomes unresponsive and the form doesn't refresh any longer until after the process is finished, thereby causing the progressbar to loose its functionality. How can I overcome this glitch? I would also like to implement a cancel button so that the user can cancel the validation process at any moment, but if a button is pressed I experience the problem mentioned above. Any help would be appreciated. Thanx. private void btnCheck_Click(object sender, EventArgs e) { using (DirectoryEntry de = new DirectoryEntry(adPath, adUsername, adPassword)) //)) { de.Username = Environment.UserName; de.AuthenticationType = AuthenticationTypes.Secure; //these are the attributes that will show string[] attribs = new string[] { "displayName", "mail", "userAccountControl" }; for (int x = 0; x < dgvManager.Rows.Count - 1; x++) { ValidateDetails(4, 5, 6, x, de, attribs); //Second in charge ValidateDetails(7, 8, 9, x, de, attribs); //Branch Manager
Sounds like you need a background worker[^] Basically, its another thread but fairly easy to work with. The problem you are getting is that your current code is running on the UI thread thus causing issues with user interaction such as button clicks etc.
Life goes very fast. Tomorrow, today is already yesterday.
-
Below is some code that validates entries in a datagridview against entries in Active Directory and changes the color of the datagridview cells accordingly. A progressbar indicates how far the process is from finish. If the user then interacts with the form either by dragging one of the datagridview scrollbars or pressing a button, the program becomes unresponsive and the form doesn't refresh any longer until after the process is finished, thereby causing the progressbar to loose its functionality. How can I overcome this glitch? I would also like to implement a cancel button so that the user can cancel the validation process at any moment, but if a button is pressed I experience the problem mentioned above. Any help would be appreciated. Thanx. private void btnCheck_Click(object sender, EventArgs e) { using (DirectoryEntry de = new DirectoryEntry(adPath, adUsername, adPassword)) //)) { de.Username = Environment.UserName; de.AuthenticationType = AuthenticationTypes.Secure; //these are the attributes that will show string[] attribs = new string[] { "displayName", "mail", "userAccountControl" }; for (int x = 0; x < dgvManager.Rows.Count - 1; x++) { ValidateDetails(4, 5, 6, x, de, attribs); //Second in charge ValidateDetails(7, 8, 9, x, de, attribs); //Branch Manager
Hardus Lombaard wrote:
A progressbar indicates how far the process is from finish. If the user then interacts with the form either by dragging one of the datagridview scrollbars or pressing a button, the program becomes unresponsive
You need to use Background worker in this case, which will help you show the progress of process with out any problem. Here is an sample application Using the BackgroundWorker Component in .NET 2 applications
Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.