如何在 C# 中暂停按钮事件?
在我的应用程序中,我想将按钮事件暂停一段时间,以便我可以触发另一个事件,然后第一个按钮事件将恢复。 在 C# 中,我不知道如何使用线程异步执行它。 请帮忙。 提前致谢..
In my application I want to suspend a button event for some time so that I can fire another event after which the first button event will resume. In c# I am not getting how do I perform it using threads asynchronously. Please help. Thanks in advance..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想触发第二个事件并等待其完成后再继续,那么为什么不在第一个事件处理程序中同步触发它呢? 那会简单得多。
编辑:
如果您希望一个按钮触发另一个按钮的事件处理程序中的代码,我建议您将其移到一个单独的函数中,然后调用它。 换句话说,这样做:
如果按钮执行完全相同的操作,您甚至可以为它们分配完全相同的处理程序。
但是,如果您确实必须以编程方式“单击”按钮,那么最简单的方法可能是:
这将引发
Click
事件。If you want to fire the second event and wait for it to finish before continuing, then why not just fire it synchronously from within the first event handler? That would be much simpler.
EDIT:
If you want one button to trigger the code that's in another button's event handler, I would suggest instead that you move it out into a separate function, and just call that. In other words, do this:
If the buttons do the exact same thing, you could even just assign them the exact same handler.
But, if you really must programmatically "click" a button, then the easiest way is probably:
That'll raise a
Click
event.这听起来像是您的应用程序中的设计问题,并且您从错误的一端解决了它。
This sounds like a design problem in your application and you're tackling it from the wrong end.
你能和后台工作人员一起做点什么吗
could you do something with background worker