0

I'd like to enable a button if some Data is available:

private void myListBox_ItemSelectionChanged(object sender, EventArgs e)
{
     downloadButton.Enabled = myList.SelectedItems.Cast<myClass.myObject>().Any(x => x.Data != null);
}

The problem is that the UI is not quite responsive, and behaves weirdly (sometimes when I click the selection does not get changed when I click and select a different element). I figured that this is because of that bit of code.

Any suggestion to speed things up?

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user2567674
  • 171
  • 1
  • 3
  • 15
  • Do the myList.SelectedItems.Cast().Any(x => x.Data != null) part in a background thread. – gregkalapos Dec 04 '15 at 12:18
  • Not a bad idea, however a new thread will be started on every click (and selection changed)..? – user2567674 Dec 04 '15 at 13:39
  • Not if you have a threadpool. First measure how long that operation takes..normally that should not be an issue... for me it's a little bit strange that something like that causes problems.. But if you already measured that this line takes too long then either you have to do that operation on a different way, or just shift the code to a background thread (which again...should be in a threadpool). Btw what is this? WPF? Store app? ...? – gregkalapos Dec 04 '15 at 13:55

0 Answers0