Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Loop making my app slow

$
0
0
So I have an event for when a ComboBox loses focus
        private void ComboUpdate(object sender, RoutedEventArgs e)
        {
            if (comboDrives.Text != null)
            {
                lblDriveName.Content = string.Format("({0}) Drive", comboDrives.Text);

                // Run slow because of this..                
                for (int i = 0; i < DiskInformation.Get().Count; i++)
                    if (DiskInformation.Get()[i].DiskName == comboDrives.Text)
                        lblDriveStatus.Content = string.Format("{0} GB free of {1} GB",
                                                       DiskInformation.Get()[i].DiskFreeSpace,
                                                       DiskInformation.Get()[i].DiskSize);
            }
        }



The for loop inside there is making my app run slow.
I'm looking for a better way of setting my label to that data.

So I select the comboBox, pick one of the drives in that box, and the labels update.
I can't think of a way of doing that outside of this loop.

Suggestions?
Thanks (:

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>