Giter Site home page Giter Site logo

Comments (8)

anaisbetts avatar anaisbetts commented on April 20, 2024

Are you calling one of the RegisterXXX methods?

Paul Betts
Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

On Thursday, August 18, 2011 at 3:20 PM, alastairs wrote:

I have created a command as follows:

IObservable canLogin = this.WhenAny(x => x.Username,
x => x.Password,
(u, p) => !string.IsNullOrWhiteSpace(u.Value) &&
!string.IsNullOrWhiteSpace(p.Value));

LoginCommand = new ReactiveAsyncCommand(canLogin);

I was expecting LoginCommand.CanExecute() to evaluate tofalse (and thereby disable the button to which the command is bound) if it is currently executing, as the constructor call above uses the default maximumConcurrent parameter value of 1. This doesn't appear to be the case.

Reply to this email directly or view it on GitHub:
https://github.com/xpaulbettsx/ReactiveUI/issues/30

from reactiveui.

alastairs avatar alastairs commented on April 20, 2024

Yup, sorry I missed that from the original code sample above (now updated). The command is executing ok, just the login button isn't becoming disabled whilst it is executing.

from reactiveui.

alastairs avatar alastairs commented on April 20, 2024

PS: you can view the full code here.

Update: fixed broken link.

from reactiveui.

anaisbetts avatar anaisbetts commented on April 20, 2024

This link 404s, can you fix it?

from reactiveui.

alastairs avatar alastairs commented on April 20, 2024

I've updated the link so it points to the correct location. Sorry for the double dose of incompetence!

from reactiveui.

anaisbetts avatar anaisbetts commented on April 20, 2024

It looks like you've set things up mostly right - let me play with this a bit and see if I can figure out what's going on

from reactiveui.

anaisbetts avatar anaisbetts commented on April 20, 2024

So, it looks like there's something wrong with Scheduler.TaskPool, it's creating a new Task, but then running it on the same thread! The code is written correctly, but because we're blocking the UI thread in a Sleep, the UI doesn't update. In the meantime, you can use the .NET 3.5 Threadpool by putting this line at startup:

RxApp.TaskpoolScheduler = System.Reactive.Concurrency.Scheduler.Taskpool;

[In a sleep, wait, or join] 
mscorlib.dll!System.Threading.Thread.Sleep(System.TimeSpan timeout) + 0x67 bytes    

GistEd.Debugging.RestClient.exe!GistEd.Debugging.RestClient.ViewModels.LoginWindowViewModel.Authenticate(RestSharp.IRestClient restClient) Line 109 + 0x22 bytes C#
GistEd.Debugging.RestClient.exe!GistEd.Debugging.RestClient.ViewModels.LoginWindowViewModel..ctor.AnonymousMethod__2() Line 38 + 0x17 bytes C#
System.Reactive.dll!System.Reactive.Linq.Observable.ToAsync.AnonymousMethod__6a() + 0x65 bytes
System.Reactive.dll!System.Reactive.Concurrency.Scheduler.Invoke(System.Reactive.Concurrency.IScheduler scheduler, System.Action action) + 0x34 bytes
System.Reactive.dll!System.Reactive.Concurrency.TaskPoolScheduler.Schedule<System.Action>.AnonymousMethod__0() + 0x92 bytes
mscorlib.dll!System.Threading.Tasks.Task.Execute() + 0x82 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xdc bytes
mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) + 0x1b5 bytes
mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) + 0xb0 bytes
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x11c bytes
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x47 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) + 0x5d bytes
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() + 0xb1 bytes
mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x178 bytes
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xa1 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x3b bytes
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x6d bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() + 0x27f bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0xb3 bytes
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x13d bytes
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x97 bytes
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x5a bytes
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x47 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) + 0x5d bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) + 0xd2 bytes
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0x164 bytes
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) + 0x13a bytes
PresentationFramework.dll!System.Windows.Window.ShowHelper(object booleanBox) + 0x229 bytes
PresentationFramework.dll!System.Windows.Window.ShowDialog() + 0x5fe bytes
GistEd.Debugging.RestClient.exe!GistEd.Debugging.RestClient.Views.LoginWindowView.GistEd.Debugging.RestClient.Interfaces.IWindow.ShowDialog() + 0x2f bytes
GistEd.Debugging.RestClient.exe!GistEd.Debugging.RestClient.Views.NinjectKernelLoader.InitializeKernel.AnonymousMethod__0(System.Threading.Tasks.Task task) Line 34 + 0x8a bytes C#
mscorlib.dll!System.Threading.Tasks.Task.Execute() + 0x9b bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xdc bytes
mscorlib.dll!System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) + 0x1b5 bytes
mscorlib.dll!System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) + 0xb0 bytes
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x11c bytes
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x47 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) + 0x5d bytes
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.InvokeImpl() + 0xb1 bytes
mscorlib.dll!System.Threading.ExecutionContext.runTryCode(object userData) + 0x178 bytes
[Native to Managed Transition]
[Managed to Native Transition]
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xa1 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x3b bytes
WindowsBase.dll!System.Windows.Threading.DispatcherOperation.Invoke() + 0x6d bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.ProcessQueue() + 0x27f bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.WndProcHook(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0xb3 bytes
WindowsBase.dll!MS.Win32.HwndWrapper.WndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam, ref bool handled) + 0x13d bytes
WindowsBase.dll!MS.Win32.HwndSubclass.DispatcherCallbackOperation(object o) + 0x97 bytes
WindowsBase.dll!System.Windows.Threading.ExceptionWrapper.InternalRealCall(System.Delegate callback, object args, int numArgs) + 0x5a bytes
WindowsBase.dll!MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(object source, System.Delegate method, object args, int numArgs, System.Delegate catchHandler) + 0x47 bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.WrappedInvoke(System.Delegate callback, object args, int numArgs, System.Delegate catchHandler) + 0x5d bytes
WindowsBase.dll!System.Windows.Threading.Dispatcher.InvokeImpl(System.Windows.Threading.DispatcherPriority priority, System.TimeSpan timeout, System.Delegate method, object args, int numArgs) + 0xd2 bytes
WindowsBase.dll!MS.Win32.HwndSubclass.SubclassWndProc(System.IntPtr hwnd, int msg, System.IntPtr wParam, System.IntPtr lParam) + 0x164 bytes
[Native to Managed Transition]
[Managed to Native Transition]
WindowsBase.dll!System.Windows.Threading.Dispatcher.PushFrameImpl(System.Windows.Threading.DispatcherFrame frame) + 0x13a bytes
PresentationFramework.dll!System.Windows.Application.RunInternal(System.Windows.Window window) + 0x12f bytes
PresentationFramework.dll!System.Windows.Application.Run() + 0xbb bytes
GistEd.Debugging.RestClient.exe!GistEd.Debugging.RestClient.App.Main() + 0x77 bytes C#
[Native to Managed Transition]
[Managed to Native Transition]
Microsoft.VisualStudio.HostingProcess.Utilities.dll!Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() + 0x48 bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool ignoreSyncCtx) + 0xdc bytes
mscorlib.dll!System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state) + 0x3b bytes
mscorlib.dll!System.Threading.ThreadHelper.ThreadStart() + 0x4d bytes
[Native to Managed Transition]

from reactiveui.

alastairs avatar alastairs commented on April 20, 2024

Thanks for spending some time to look at this. I'm sorry that your proposed fix doesn't work for me.

I'm wondering, given what you found, whether my initialisation code is incorrect. To begin with, I display a loading window to set up my Ninject kernel, after which I run the rest of the app (starting with the login window). I have set the continuation running the app to run on the Dispatcher, so that the windows can be created successfully:

private void InitializeKernel()
{
    // Create a scheduler for the WPF Dispatcher.
    var scheduler = TaskScheduler.FromCurrentSynchronizationContext();

    Task.Factory.StartNew(() =>
                              {
                                  Kernel = new StandardKernel();
                                  Kernel.Load<GitHubRestClientAppModule>();
                              })
                .ContinueWith(task =>
                                  {
                                      Hide();

                                      if (Kernel.Get<IScreenFactory>().GetLoginWindow().ShowDialog() == false)
                                      {
                                          Application.Current.Shutdown();
                                      }
                                      Kernel.Get<IScreenFactory>().GetMainWindow().Show();
                                  }, scheduler);
}

This should ensure the continuation thread runs on the WPF Dispatcher, but I'm wondering if it's also messing up the Scheduler for RxApp as you suggested. Unfortunately, neither placing your proposed fix before the Task.Factory.StartNew() nor in the ContinueWith() fixes the issue. I even tried the constructor of my ViewModel (before the login command is set up) to no avail.

from reactiveui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.