I am creating a plugin with a ScheduleTask which will call an external webservice that i have no control over.
This webservice is returning a very long list of products, and the call takes 3-4 minutes.
Thats more than the default timeout value of the WebClient which the TaskThread.cs is using:
using (var client = new WebClient())
{
client.UploadValues(_scheduleTaskUrl, postData);
}
That part i can solve by using async/await on my Execute method like this:
public async void Execute()
{
await GetData();
_aoProductService.SaveData(_variantData, _updaterName);
}
Now my problem is that i need to save that data to my database.
I do that by calling this method:
_aoProductService.SaveData which has been instanciated by Depencency Injection.
That will cause an error as the context has been disposed by the await call.
Error:
"Cannot access a disposed object. A common cause of this error is disposing a context that was resolved from dependency injection and then later trying to use the same context instance elsewhere in your application. This may occur if you are calling Dispose() on the context, or wrapping the context in a using statement. If you are using dependency injection, you should let the dependency injection container take care of disposing context instances.
Object name: 'NopObjectContext'."
Is there any other way of doing this. (maybe a good way of increasing the timeout of the WebClient?
Any help will be appreciated.
Best regards,
Axel