ブロックを解除していないように見える使用している ManualResetEvent について少し混乱しています。なぜこれが当てはまるのか誰にも分かりますか?
私が持っているシナリオは、これらの線に沿ったものです。実際の状況は非常に複雑で、問題を再現するために投稿するのが妥当なコードのセクションを分離することができませんでした。
EDIT
以下のコード例を更新しました。これはさまざまなダイアログで実行され、そのうちの 1 つが this.mre.WaitOne(); にヒットすることに気付きました。次に、「サーバービジー」ダイアログが表示され、「切り替え」または「再試行」を押す必要があります。これにより、コードが WaitOne() 呼び出しを通過し、すべてが機能します。それがどのように関連しているかはわかりませんが、明らかに重要なものです。
public class A
{
ManualResetEvent mre;
public void Start(ThreadClass tc)
{
this.mre = new ManualResetEvent(false);
tc.Begin();
WebClient wc = new WebClient();
// progress events are pumped to the ThreadClass which then update the Form2.
wc.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(wc_DownloadFileCompleted);
wc.DownloadFileAsync("Src", "Tgt");
this.mre.WaitOne();
}
void void wc_DownloadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e)
{
try
{
// Do Stuff
}
finally
{
this.mre.Set();
}
}
}
public class ThreadClass
{
Begin()
{
Thread t = new Thread(new ThreadStart(DoWork));
t.Start();
}
private void DoWork()
{
Form f = new Form2();
f.ShowDialog();
// Sits waiting on another ResetEvent to determine when to close the thread.
}
}