ImageList.Images.Clear()を別のスレッドから呼び出すにはどうすればよいですか?私はImageList.Images.Clear()を別のスレッドからどのように呼び出すのですか?
private delegate void SetControlPropertyThreadSafeDelegate(Control control, string propertyName, object propertyValue);
public static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
{
if (control.InvokeRequired)
{
control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
}
else
{
control.GetType().InvokeMember(propertyName, System.Reflection.BindingFlags.SetProperty, null, control, new object[] { propertyValue });
}
}
のような機能を実行しようとしましたが、私はちょうどあなたができる
ImageList.Images.Clear()
スレッドのコンテキストを把握する必要があります。今は痛みのように思えるかもしれませんが、将来この権利を得るために時間を節約することができます。 –
あなたのコードには1つの問題があります - コントロール/その親の 'Handle'が作成されていない場合' InvokeRequired'は 'false'を返します。あなたのコードを最初に使う前に、UIスレッド上に 'Handle'が作成されていることを確認しなければなりません。さもなければ、あなたのアプリケーションは奇妙な問題に遭遇します! – Yahia