Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImpromptuMVVM: Dispatcher thread awareness #5

Closed
jbtule opened this issue May 10, 2013 · 1 comment
Closed

ImpromptuMVVM: Dispatcher thread awareness #5

jbtule opened this issue May 10, 2013 · 1 comment

Comments

@jbtule
Copy link
Member

jbtule commented May 10, 2013

Reported by @WorldMaker Sep 21, 2012

Description of feature:

Silverlight, WPF, and Win8 all use a threading model where UI changes need to be marshalled (back) onto a "Dispatcher" thread (the UI thread). Good performant apps run operations on a background thread and then marshall changes back to the UI/Dispatcher thread.

C# 4.5 support for the async/await keywords help mitigate handling this dispatcher thread work in non-MVVM event handlers and it would nice for ImpromptuMVVM to support Dispatcher thread awareness as well.

The suggestion here would be to add the necessary checks to the pieces that call INotifyPropertyChanged, CommandExecuteChanged, etc events to check if they are running on the appropriate Dispatcher thread, and if they are not to call the suitable BeginInvoke(...) to do so.

A further suggestion to help make even easier to "do things the right way by default" would be to either default impromptu Commands to run on a background thread. It may be a breaking change to do that, so a better suggestion may be to support impromptu Commands that return Task (and by extension the C# 4.5 async keyword) and make sure those run in a background thread.

Usage case:

Contract.Prop1 = "value";
// ...more operation code here...
Dynamic.Prop2 = "other value";

Instead of:

App.Current.Dispatcher.BeginInvoke(() =>
{
Contract.Prop1 = "value";
});
// ...more operation code here...
App.Current.Dispatcher.BeginInvoke(() =>
{
Dynamic.Prop2 = "other value";
});

Also:

// Background commands
public Task Save(object p) {}
public async void Save(object p) {}

Notes:

I'm willing to contribute code to support this, but before I started coding something for this I wanted to make sure I reported it as a feature request to get a feel for whether or not there is deeper interest in this idea and if it feels like something that should indeed be a part of ImpromptuMVVM.
Oct 26, 2012 Delete comment Project Member jtuley
I think the dispatcher idea is a really good one. The task async stuff, is interesting, I think the backwards compatibility without much overhead could be done with a slight syntax change such as CommandAsync.Save or something to that effect. Would welcome code.

FYI on my github I have my more bleeding edge stuff now. including the solution updated for VS2012 https://github.com/jbtule/impromptu-interface
Nov 3, 2012 Delete comment max.battcher
I forked it on github last weekend and think I actually got this coded. I haven't sent a pull request yet because I think I want to build a simple quick WPF app to test it a bit, but the code is there if you want to see what I've attempted:

https://github.com/WorldMaker/impromptu-interface
Jan 12, 2013 Delete comment max.battcher
Quick update that in the last few weeks I've moving towards a different approach to similar ideas here: I've been working in small amounts of spare time to try my hand at hybridizing ImpromptuInterface.MVVM with ReactiveUI (reactiveui.net)...
Jan 31, 2013 Delete comment max.battcher
I've posted my port of ImpromptuInterface.MVVM on top of ReactiveUI thus far to github: https://github.com/WorldMaker/ReflexUX

There is still a bunch of things on my TODO list and it needs a sample application, but there should be enough code there to get an idea of what I'm trying to do with it. I'd appreciate any feedback you might have.
Jan 31, 2013 Delete comment Project Member jtuley
Wish I was more familiar with ReactiveUI, looks clean, very interested in seeing a sample app! Made some comments on git hub too.
Jan 31, 2013 Delete comment max.battcher
Yes, thanks a lot for the comments. Here's my first crack at a sample app by forking and branching an existing RxUI sample: https://github.com/WorldMaker/RxUI_QCon/tree/reflex

There's still plenty I want to do with this, but I think this shows a good start.

@jbtule
Copy link
Member Author

jbtule commented Aug 19, 2017

MVVM is gone

@jbtule jbtule closed this as completed Aug 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant