Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>not sure, but if you remove the <code>await</code> - does it help ?</p> <p>EDIT:</p> <p>I am no expert on C# 5 but what I gather that <code>await</code> wait for the launched task(s) to finish... it is a way to synchronize so the after the <code>await</code> the result be accessed without further checking whether the task(s) already finished... From the post I think that <code>await</code> is not needed and that it somehow "blocks" the <code>OnPropertyChange</code> call from the insise the launched Task.</p> <p>EDIT 2 - another try:</p> <pre><code>if (dlg.ShowDialog() == true) { string FN = dlg.FileName; Task.Factory.StartNew(() =&gt; ReadExcelFile(FN)); } </code></pre> <p><strong>EDIT 3 - solution (without C# 5 though):</strong></p> <p>I created a fresh WPF app, put 2 buttons (<code>button1</code> => select excel file, <code>button2</code> => Save) in the designer... I removed all "<code>OnPropertyChanged</code>" calls (I used <code>this.Dispatch.Invoke</code> instead)... <code>RelayCommand</code> is 1:1 from <a href="http://msdn.microsoft.com/en-us/magazine/dd419663.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/magazine/dd419663.aspx</a> ... following is the relevant changed source:</p> <pre><code>private void SelectExcelFile() { var dlg = new Microsoft.Win32.OpenFileDialog(); dlg.DefaultExt = ".xls|.xlsx"; dlg.Filter = "Excel documents (*.xls, *.xlsx)|*.xls;*.xlsx"; if (dlg.ShowDialog() == true) { Task.Factory.StartNew(() =&gt; ReadExcelFile(dlg.FileName)); } } private List&lt;int&gt; _fileContents = new List&lt;int&gt;(); public List&lt;int&gt; FileContents { get { return _fileContents; } set { if (value != _fileContents) { _fileContents = value; this.Dispatcher.Invoke ( new Action (delegate() { button2.IsEnabled = true; button2.Command = SaveCommand; }),null); } } } private void button1_Click(object sender, RoutedEventArgs e) { button2.IsEnabled = false; button2.Command = null; SelectExcelFileCommand.Execute(null); } private void button2_Click(object sender, RoutedEventArgs e) { SaveCommand.Execute(null); } </code></pre> <p>all problems described by the OP are gone: the Excel reading is on another thread... the UI does not freeze... the <code>Savecommand</code> gets enabled if the Excelreading is successfull...</p> <p>EDIT 4:</p> <pre><code> this.Dispatcher.Invoke(new Action(delegate() { CommandManager.InvalidateRequerySuggested(); }), null); </code></pre> <p>you can use this instead of the <code>IsEnabled</code>... causes the <code>CanExecuteChanged</code> event to be fired without "rebuilding" the <code>SaveCommand</code> (which causes the <code>CanExecuteChanged</code> event to be unregistered and then reregistered)</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload