I am currently trying to use a Timer (System.Timers) within a Blazor component to update an entity using an Injected DBContext. However when it reaches the Save Changes method it simply shows the following error
Here is the my Startup.cs file DbContext section:
My Blazor Component CS looks like this:
What I think the Problem Is
I think the problem is that the Timer class is on a different thread and therefore isn't in scope to access to the DbContext.
What I don't know is, if I am right, how to pass the DbContext properly to the Timer or how to call the Save Changes method from the main thread.
I did try to use a DBContextPool (as shown below) but it doesn't work. I am guessing it's still due to the thread being different from the main thread.
If you need any more details please just let me know so I can gather the exact details.
Update 1 07/20/2020
I attempted to move the logic into a service. That service then has a DbContext injected into it however I got the same error message but the error happened in the new ActionService class.
Here is the new ActionService
And here is the Startup.cs change
Here is the Blazor Component Update