- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
哪个更正确,为什么?
Control.BeginInvoke(new Action(DoSomething), null);
private void DoSomething()
{
MessageBox.Show("What a great post");
}
或
Control.BeginInvoke((MethodInvoker) delegate {
MessageBox.Show("What a great post");
});
我有点觉得我在做同样的事情,那么什么时候使用 MethodInvoker
vs Action
,甚至写一个 lambda 表达式?
编辑:我知道编写 lambda 与 Action
之间并没有太大区别,但是 MethodInvoker
似乎是为特定目的而制作。它有什么不同吗?
最佳答案
两者都同样正确,但是 Control.Invoke
的文档指出:
The delegate can be an instance of EventHandler, in which case the sender parameter will contain this control, and the event parameter will contain EventArgs.Empty. The delegate can also be an instance of MethodInvoker, or any other delegate that takes a void parameter list. A call to an EventHandler or MethodInvoker delegate will be faster than a call to another type of delegate.
所以 MethodInvoker
会是一个更高效的选择。
关于c# - MethodInvoker 与 Control.BeginInvoke 的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1167771/
我对 Dispatcher.CurrentDispatcher.BeginInvoke 和 BeginInvoke 之间的区别感到困惑 我有以下部分代码不起作用,UpdateCounts 方法中的代码
我最初尝试使用 Dispatcher 类 BeginInvoke 方法在我的 C# Windows 窗体应用程序的主 UI 线程上显示消息框。当我使用该方法时,消息框没有出现。我在传递给 BeginI
伙计们! 我的.net应用程序有问题。当我尝试在程序中打印时,它会崩溃崩溃 与任何错误消息。我从Windows中的事件查看器中获得的有关错误的信息。有人能帮我吗?但是在另一台计算机上它可以正常工作。我
我有简单的(我认为的)逻辑。 public static void NotifyAboutNewJob(int jobId, bool forceSending = false) {
我有一个 c# .NET winforms 应用程序进行此异步调用: simpleDelegate.BeginInvoke(null, null); 委托(delegate)正在调用我的函数,一切正常
1) 我听说当我们不调用 EndInvoke() 时可能会导致内存泄漏?你能演示一下这怎么会导致内存泄漏吗? 2) 当我想调用 EndInvoke() 时,我应该使用如下代码吗? namespace
我遇到了在多线程应用程序中使用 Dispatcher.BeginInvoke 导致的我无法理解的错误。 我的程序包含一个 List 对象,我使用多个线程循环遍历这些对象并执行一些计算。我已将我的代码结
我正在研究其他人的代码,但对多线程没有太多经验。我遇到了这行代码: BeginInvoke((MethodInvoker)delegate() { btnCalibrate.PerformClick(
我继承了从主线程调用 BeginInvoke 的代码(不是后台线程,通常是这种模式)。我试图了解它在这种情况下的实际作用。 在 BeginInvoke 中调用的方法是否符合下行到窗口的消息?文档说 a
为什么会出现此错误以及如何修复它。感谢帮助 错误 4 无法将 lambda 表达式转换为类型“System.Delegate”,因为它不是委托(delegate)类型 void provide
我在 WPF 应用程序中有一些代码如下所示: public class MyTextBox : System.Windows.Controls.TextBox, IDisposable { p
我有以下问题。 FindRoot 实际上在第三方 dll 中,我无法控制它。 它必须通过 Begin invoke 调用。有时,FindRoot 方法会抛出异常。这导致我的整个应用程序崩溃。现在,即使
这个问题在这里已经有了答案: Does Func.BeginInvoke use the ThreadPool? (2 个答案) 关闭 1 年前。 在我的 WPF 应用程序中,我想在非 UI 线程中
我是线程和异步编程的新手。我正在尝试学习这些概念,到目前为止,我已经理解了,但是还有一个问题要问。 可以说我想调用一个名为GetAllUsers()的方法,该方法需要很长时间才能执行,因此它不会阻塞资
我已经看到(并阅读)关于使用 Dispatcher.BeginInvoke 来确保 UI 更新发生在 UI 线程上。我明白这个道理。 但是我看到了在 View 代码隐藏中分配属性(例如 TextBlo
我想确定使用 BeginInvoke 时执行处理程序的线程。现在,每次我调用该方法时,处理程序都会由不同的线程执行。有没有办法确定线程? using System; using System.Thre
我有一个长时间运行的函数¹: public string FindPasswordFromHash(String hash) { ... } 它被称为: private void Button
我找不到这个简单问题的答案:BeginInvoke() 是否保证以原子方式执行被调用的委托(delegate)?例如,如果我有类似的东西 public ObservableCollection Ite
我收到一个 InvalidOperationException 消息 Cross-thread operation not valid.. _waitForm 是在主窗体的构造函数中创建的。屏幕截图中
我是编码新手,在我的第一个项目中,我必须从数显卡尺读取信息并将其显示在网络应用程序的文本框中。我从另一个项目中找到了代码,其他人在他们使用 Windows 窗体的地方创建了这些代码。我正在使用 vis
我是一名优秀的程序员,十分优秀!