You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I create a WPF Command with Factory.CommandAsyncChecked(asyncWorkflow, canExecute), and bind that command to a button, and click the button, the button becomes disabled and does not become re-enabled until the asyncWorkflow completes. It does this even if canExecute always returns true.
Repro steps
Create a new F# project
Reference FSharp.ViewModule.Core, 0.9.9.2 and FsXaml.Wpf, 0.9.9.
Use the code below.
Run the program. Press the button.
Observe that the button becomes disabled for three seconds and then becomes re-enabled.
open System
open System.Windows
open FSharp.ViewModule
type MainWindow = FsXaml.XAML< "MainWindow.xaml", true >
type MainWindowViewModel() as this =
inherit ViewModelBase()
let asyncWorkflow _ =
async {
do! Async.Sleep(3000)
System.Diagnostics.Debug.WriteLine("asyncWorkflow completed.")
}
let canExecute _ = true
member val DoSomethingAsync =
this.Factory.CommandAsyncChecked(asyncWorkflow, canExecute)
[<STAThread; EntryPoint>]
let main argv =
if SynchronizationContext.Current = null then
DispatcherSynchronizationContext(Dispatcher.CurrentDispatcher)
|> SynchronizationContext.SetSynchronizationContext
let win = MainWindow()
win.Root.DataContext <- MainWindowViewModel()
let app = Application()
app.Run(win.Root)
Expected behavior
I expected that the button would never become disabled.
Actual behavior
The button becomes disabled for three seconds.
Known workarounds
None.
Related information
Windows 10
Visual Studio 2015
.NET Framework 4.5.2, FSharp.Core 4.4.0.0
The text was updated successfully, but these errors were encountered:
Looking back at this, I believe this is by design.
If you want to avoid it, you can use a Sync command that just starts an async workflow. The entire reason behind the separate Async command support was to allow it to track execution and disable.
I believe you can "workaround" this behavior if you don't like the defaults by doing:
typeMainWindowViewModel()as this =inherit ViewModelBase()letasyncWorkflow _ =async{do! Async.Sleep(3000)
System.Diagnostics.Debug.WriteLine("asyncWorkflow completed.")}|> Async.Start
member valDoSomethingAsync= this.Factory.CommandSync(asyncWorkflow)
Description
When I create a WPF Command with
Factory.CommandAsyncChecked(asyncWorkflow, canExecute)
, and bind that command to a button, and click the button, the button becomes disabled and does not become re-enabled until the asyncWorkflow completes. It does this even ifcanExecute
always returns true.Repro steps
MainWindow.xaml
Program.cs
Expected behavior
I expected that the button would never become disabled.
Actual behavior
The button becomes disabled for three seconds.
Known workarounds
None.
Related information
The text was updated successfully, but these errors were encountered: