私は、設計が不十分なソリューションに悩まされてきました。スレッドセーフではありません!
ソリューションにはいくつかの共有クラスとメンバーがあり、開発中はすべてクールでした...
BizTalk は私の戦艦を沈めました。
カスタム BizTalk アダプターを使用してアセンブリを呼び出しています。アダプターは私のコードを呼び出して並行して実行しているため、同じ AppDomain の下ですべて複数のスレッドを使用していると思います。
私がやりたいことは、自分のコードを独自の AppDomain の下で実行することです。これにより、私が抱えている共有の問題が互いに干渉することはありません。
BizTalk アダプターがインスタンス化してから Process() メソッドを実行する非常に単純なクラスがあります。
Process() メソッド内に新しい AppDomain を作成したいので、BizTalk が別のスレッドをスピンするたびに、独自のバージョンの静的クラスとメソッドが作成されます。
BizTalkAdapter コード:
// this is inside the BizTalkAdapter and it is calling the Loader class //
private void SendMessage(IBaseMessage message, TransactionalTransmitProperties properties)
{
Stream strm = message.BodyPart.GetOriginalDataStream();
string connectionString = properties.ConnectionString;
string msgFileName = message.Context.Read("ReceivedFileName", "http://schemas.microsoft.com/BizTalk/2003/file-properties") as string;
Loader loader = new Loader(strm, msgFileName, connectionString);
loader.Process();
EventLog.WriteEntry("Loader", "Successfully processed: " + msgFileName);
}
これはクラス BizTalk コールです。
public class Loader
{
private string connectionString;
private string fileName;
private Stream stream;
private DataFile dataFile;
public Loader(Stream stream, string fileName, string connectionString)
{
this.connectionString = connectionString;
this.fileName = fileName;
this.stream = stream;
}
public void Process()
{
//***** Create AppDomain HERE *****
// run following code entirely under that domain
dataFile = new DataFile(aredStream, fileName, connectionString);
dataFile.ParseFile();
dataFile.Save();
// get rid of the AppDomain here...
}
}
参考までに: Loader クラスは、dataFile クラスとは別の DLL にあります。
どんな助けでも大歓迎です。コードをスレッドセーフにする作業を続けますが、これが「単純な」答えになると思います。
他に思い当たる人がいたら、どうぞ。
ありがとう、
キース
完全を期すためだけに。
「Transport Advanced Options」ダイアログで送信アダプタを「Ordered Delivery」としてマークすると、発生していたマルチスレッドの問題を回避できることがわかりました。
これは私の問題に対する別の可能な答えだと思いますが、必ずしも質問に対するものではありません。