如何从另一个线程调用 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 没有 InvokeRequired 或 Invoke,而且我不想设置属性,我只想调用
ImageList.Images.Clear()
How do I call ImageList.Images.Clear() from another thread? I tried to do a function like
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 });
}
}
but ImageList doesn't have an InvokeRequired or Invoke, plus I don't want to set a property, I just want to call
ImageList.Images.Clear()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用它:
这将异步调用 UI 线程上的委托。如果您需要立即清除列表,请将“发布”替换为“发送”。当然,您还需要对要清除的 ImageList 的引用。
You can use this:
This will asynchronously invoke the delegate on the UI thread. If you need to immediately clear the list replace Post with Send. Of course you also need the reference to the ImageList you want to clear.