Maverick (Shaun)
Invoke StateHasChanged() only after asynchronous operation has completed
Ended up taking an alternative approach by navigating to the same page (essentially a reload) using NavigationManager with a forced refresh - thanks for the messages folks
20 replies
Invoke StateHasChanged() only after asynchronous operation has completed
I guess a lack of behaviour would be a better description - nothing changes until I manually refresh the screen. I suppose there's a chance that
StateHasChanged
isn't actually refreshing the page as I'd expect, but it works everywhere else so I reckon my assumption that StateHasChanged
is being invoked before the database is actually updated is more likely20 replies
Invoke StateHasChanged() only after asynchronous operation has completed
I see. However, I am not seeing a change in behaviour when switching the method to
async Task
, when calling it with:
As far as I know, Blazor will detect that the method is asynchronous and handle it as such in the event handler above. I'm still not quite sure how awaiting PublishDrawWithConfirmation
will affect the call to StateHasChanged
within that method, but that's probably due to my lack of experience/in-depth understanding of asynchronicity20 replies
Invoke StateHasChanged() only after asynchronous operation has completed
What difference would that make? Not disputing it, just not following how that would affect things logically. The call to StateHasChanged is happening inside of this function, so surely just changing the return type wouldn't make a difference? if I move the call to StateHasChanged outside of the function and then await the function and call StateHasChanged, wouldn't I just get the same behaviour as I currently am?
20 replies
Multiple Blazor components accessing database via single DbContext at same time
Made the change, tested that existing functionality was behaving as before and checked if the code that was causing issues with concurrency is now working - everything seems fine, very simple change and can't see any problems yet. Awesome stuff :goodthinking:
21 replies
Multiple Blazor components accessing database via single DbContext at same time
I assume the change to my services (e.g.):
Would be as simple as just passing the context to the CRUD methods rather than having it in the service constructor?
21 replies
Multiple Blazor components accessing database via single DbContext at same time
Wow, that' s a lot simpler than I was expecting. I was having a skim read of some StackOverflow threads covering this topic and there seemed to be a lot of try-catch stuff bloating the code... not sure what they were doing to end up with that, my first thought was "that isn't very DRY". Seems it's definitely worthwhile then, I'd of course like to use best practices wherever I can as long as it doesn't add a ton of complexity
21 replies
Multiple Blazor components accessing database via single DbContext at same time
How much of a problem is that likely to be? This is for a university project and won't actually be running for too long at once. I'm assuming that'd be more of an issue for an application that's running for long periods of time?
21 replies
Multiple Blazor components accessing database via single DbContext at same time
I've had a think about it, and I think this is the only instance in my application where this problem will occur. Since I'm only needing access to a couple of strings (Title and Description of the relevant model), I've decided just to get the object in the parent component and then pass the Title and Description to the child components directly, avoiding concurrent calls to dbcontext. I think this maybe breaks some "rules" regarding security, but since these strings don't contain any sensitive information, I think it's probably okay. Would you agree? Avoids adding a layer of complexity to the project and gets the same job done
21 replies