Hi,
I'm wondering if it is safe to do code like this:
(SelfServicing)
in my main thread (dfc is an EntityCollection):
foreach(DataFileEntity df in dfc)
{
AutoResetEvent waitEvent = new AutoResetEvent(false);
waitHandles.Add(waitEvent);
FileProcessorThreadState state = new FileProcessorThreadState();
state.WaitEvent = waitEvent;
state.DataFile = df;
ThreadPool.QueueUserWorkItem(
new WaitCallback(FileProcessor.Go),
state);
}
the threadstate class:
class FileProcessorThreadState
{
public AutoResetEvent WaitEvent;
public DataFileEntity DataFile;
}
and the thread worker:
class FileProcessor
{
public static void Go(object state)
{
FileProcessorThreadState threadState = (FileProcessorThreadState)state;
<snip>
threadState.DataFile.Save();
threadState.WaitEvent.Set();
}
}
Code simplified to show the concept.... I guess the simple version is: Is it safe to update and save a SelfServicing entity on a different thread to the one it was created on ?
Luckily (perhaps) the entity is not involved in a Transaction. I doubt I'd consider this approach if that was the case.
Thanks in advance for any comments and advice.
Regards
Mike