Custom Task and Entity Framework exception

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 лет назад
I have a custom task that is executed every n seconds in a separate thread.
One function of the task is to set orders to 'shipped'.

Since the upgrade to nop 1.8, the line below throws an exception 'An entity object cannot be referenced by multiple instances of IEntityChangeTracker'.

OrderManager.Ship(ordernumber, true);        (where ordernumber is an int value)

I have read this post, but this does not help me, or at least I'm not sure what's going wrong here.
Anyone has an idea?

Thanks!
13 лет назад
We've experienced this a few time when working with the objectcontext on different threads.

Typically we get around it by getting the entity within our custom task/method i.e. context.Orders.SingleOrDefault(x=> x.OrderId == orderid) rather than using the GetEntitybyId methods.

Hope that helps,
Ben
13 лет назад
Thanks Ben,

The strange thing is that I don't get any entity within the task. I just use the function

OrderManager.Ship(ordernumber, true);

The ordernumber is fetched from an email message.
It does a few checks (not on the actual Order object, but other third-party properties) and then calls the mentioned function by passing the order number.
13 лет назад
The changes that are in 1.7/1.8 have more effect on running Tasks then I expected.

Besides the exceptions that are thrown while saving the Order using the OrderManager.Ship method, it also seems that other methods, like MessageManager.SendOrderShippedCustomerNotification have troubles being called from a Task.
This is because inside the calls, there are one or more functions that use HttpContext.Current.Request and since a Task is run without a Request, it seems this can't be handled easy from a Task.

Does anyone have suggestions about how to handle such a scenario?
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.