Comments (12)
@fcogutierrez please take a look at this.
https://gist.github.com/programmation/6cc84cfce8e296596364
I've also done this in the past.
Task.Factory.StartNew(() => MyTask(), TaskCreationOptions.LongRunning);
from freshmvvm.
Great thanks. I'm just away at the moment but I will look at this asap.
from freshmvvm.
Will the @BNoohi branch be merged in, maybe as an expansion of the IPageModelCoreMethods interface to avoid breaking changes?
from freshmvvm.
@rid00z Waiting on your thoughts on this.
from freshmvvm.
@BNoohi I'm planning on look at this in the next 5 days, along with some other new features for FreshMvvm. :)
from freshmvvm.
@BNoohi thanks for your work in doing this, I very much appreciate it.
Hi, so I've actually taken a look at this and the side effects of using this isn't worth the pay off. There's a big ripple effect in the whole Framework/App. In addition we don't really want to be waiting at this point, we went to kick off a background task.
We can solve this problem by using the pattern below. What do you think?
public override void Init (object initData)
{
LongRunningTask ().RunForget ();
}
async Task LongRunningTask()
{
//show loading screen
await Task.Delay (5000);
Contacts = new ObservableCollection<Contact> (_databaseService.GetContacts ());
//stop loading screen
}
from freshmvvm.
Closed, but open to comment? @rid00z I don't think that pattern actually addresses the issue at hand, which is testing of the method and exception handling of the task.
I provided the code as is for option one, but what about option 2? What were your thoughts on that? It should be similar to what you suggested but allows for MSDN best practices and exception handling.
That is, change the method to an async Task but then the line that calls Init() we call with a Task.Run() allowing it to be a fire and forget. Same as it is now, only it can actually throw if something fails in that initialization.
from freshmvvm.
Actually that solution addresses all the issues. It's testable because you can test both the init method and the long running task. It works according to MSDN best practices, eg you not doing async void. How do you think it doesn't work according with MSDN practices?
Option 2 just moves the problem, as you need to await Task.Run anyway and if you don't await Task.Run then the logic ordering will not be in sync.
from freshmvvm.
You're right, with my point being with option 2 is to not await the Task when calling Init, they end up being similar.The only thing is with Init itself having a void type and the tasks set to forget, it's not easy testing that the Init method calls and handles the tasks. You're right that the task you're calling is testable, the issue is Init itself calling the tasks.
from freshmvvm.
Hello, what is the solution here? Because the RunForget method does not exist...
from freshmvvm.
newb question - so if a pagemodel needs to invoke an async method to get its data, how to do if Init itself is not async ?
from freshmvvm.
@papiermache Try putting the async calls in an overridden FreshBasePageModel.ViewIsAppearing() method.
protected override async void ViewIsAppearing (object sender, EventArgs e)
from freshmvvm.
Related Issues (20)
- CoreMethods PopPageModel() throws exception when page contains CarouselView HOT 1
- using <Path> in XAML throws TinyIoCResolutionException
- ReverseInit not called HOT 1
- XF 5 MasterDetailPage to FlyoutPage HOT 1
- Correct way to handle Button Clicks and updating the model HOT 1
- Hamburger Menu is displayed in the Content Page in Landscape Orientation - Android HOT 1
- Project status and plans for .NET MAUI HOT 10
- Page not loaded properly for PopPageModel using navigation stack in FreshMVVM Xamarin Forms Android HOT 1
- SetBackButtonTextProperty doesn't work HOT 1
- How to intercept software back button press on FreshMVVM PageModel? HOT 3
- v4.0 Release notes?
- SIGABRT: Popped page does not appear on top of current navigation stack, please file a bug. IOS Xamarin HOT 2
- Can not run sample App in VS2019
- Fody Propertychanged on Viewmodels
- PushPageModel does not work after the app ran in the background
- Implement same bevaviour as at PRISM IDestructible HOT 4
- Update view after update bind property in ViewModel
- Cannot resolve IFreshNavigationService from a page loaded from Notifcation tap HOT 1
- FreshMVVM MAUI support
- Issue 'NavGraph cannot be null' with FreshMasterDetailNavigationContainer since MAUI 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from freshmvvm.