Tokens and Threads
Posted: Mon Aug 17, 2009 10:23 pm
G'day guys,
I have a couple of worker functions that need to run in the background, so that the page isn't being held up (and I'm using a polled AJAX update panel).
I have considered using the BackgroundWorker class, but would like this to works as I have alot of code that is threaded in a classic manner.
The issue is that one of the worker functions, which deletes products, categories, manufacturers and vendors, when in another managed thread, doesn't work.
The function uses a simple:
And the other foreach loops for the categories, manufacturers and vendors.
This function works if it is not threaded, that is, if it's in the code behind the button.
The Token.Instance.Store.Products collection is seemingly empty.
I have tried the following code before the foreach statements:
Where the StoreID is stored in a static int, which is equalling the correct value (this I have checked),
But it still doesn't delete the items.
Any help is greatly appreciated,
The wall I'm banging my head against is getting sick of me.
I have a couple of worker functions that need to run in the background, so that the page isn't being held up (and I'm using a polled AJAX update panel).
I have considered using the BackgroundWorker class, but would like this to works as I have alot of code that is threaded in a classic manner.
The issue is that one of the worker functions, which deletes products, categories, manufacturers and vendors, when in another managed thread, doesn't work.
The function uses a simple:
Code: Select all
foreach (Product prod in Token.Instance.Store.Products)
{
++prodCount;
if (prod != null)
prod.Delete();
}
This function works if it is not threaded, that is, if it's in the code behind the button.
The Token.Instance.Store.Products collection is seemingly empty.
I have tried the following code before the foreach statements:
Code: Select all
Token.Instance.Store = new Store(StoreID);
But it still doesn't delete the items.
Any help is greatly appreciated,
The wall I'm banging my head against is getting sick of me.