Hi ^_^
Just when I think my Workflow Engine is in order, this happens >_<<br mode="hold" />
So, I have an instance of an IMessage that I need to clone. here is that process:
public IMessage Requeue()
{
var message = Clone();
if (ReferenceEquals(message, this))
{
throw new InvalidOperationException("Clone must return a different object!");
}
message.Id = 0;
message.Started = false;
message.Complete = false;
message.ReadTimestamp = null;
message.CompleteTimestamp = null;
message.Due = DateTime.Now + TimeSpan.FromSeconds(10);
message.Save();
return message;
}
protected virtual IMessage Clone()
{
IMessage message = (IMessage)Activator.CreateInstance(GetType());
message.SerializedData = Serialize();
message = DeSerialize(message);
return message;
}
public string Serialize()
{
Type thisType = GetType();
var serializer = new XmlSerializer(thisType);
TextWriter writer = new StringWriter();
serializer.Serialize(writer, this);
return writer.ToString();
}
The messages need to carry forward the derived type property values or the process is useless. I caught a case at
message.Save();
where the SerializedData was null and reran the
Clone()
method. That time it worked.
My message parser is multi-threaded, but each message parse is handled in a single thread from start to finish (including re-queuing a clone).
I don't get why this isn't working unless
XmlSerializer
has some race condition issues or is not truly thread-safe. I couldn't find any evidence of this online, but I'm close to writing my own XmlSerializer. It seems like it would be easy enough but I don't want to if I don't have to.
Any advice would be appreciated
Thanks ^_^
Andy