草庐IT

begininvoke

全部标签

c# - delegate.BeginInvoke 和在 C# 中使用 ThreadPool 线程的区别

在C#中,使用委托(delegate)异步执行某些工作(调用BeginInvoke())和使用ThreadPool线程之间有什么区别,如下所示publicvoidasynchronousWork(objectnum){//asynchronousworktobedoneConsole.WriteLine(num);}publicvoidtest(){ActionmyCustomDelegate=this.asynchronousWork;intx=7;//UsingDelegatemyCustomDelegate.BeginInvoke(7,null,null);//UsingThre

c# - 扩展 Control 以提供始终如一的安全 Invoke/BeginInvoke 功能是否合适?

在维护严重违反winforms中跨线程更新规则的旧应用程序的过程中,我创建了以下扩展方法,作为一种在发现非法调用时快速修复它们的方法://////Executeamethodonthecontrol'sowningthread.//////Thecontrolthatisbeingupdated.///ThemethodthatupdatesuiElement.///Truetoforcesynchronousexecutionof///updater.Falsetoallowasynchronousexecutionifthecallismarshalled///fromanon-G

c# - C#调用BeginInvoke/Invoke时如何获取返回值

我有这个应该是线程安全的小方法。一切正常,直到我希望它具有返回值而不是无效。调用BeginInvoke时如何获取返回值?publicstaticstringreadControlText(ControlvarControl){if(varControl.InvokeRequired){varControl.BeginInvoke(newMethodInvoker(()=>readControlText(varControl)));}else{stringvarText=varControl.Text;returnvarText;}}编辑:我猜想在这种情况下拥有BeginInvoke并不

c# - 调度程序 BeginInvoke 语法

我一直在尝试遵循一些WCF数据服务示例并具有以下代码:privatevoidOnSaveCompleted(IAsyncResultresult){Dispatcher.BeginInvoke(()=>{context.EndSaveChanges(result);});}由以下调用:this.context.BeginSaveChanges(SaveChangesOptions.Batch,this.OnSaveCompleted,null);现在我在这里有点困惑。首先,代码的第一位显示语法错误Argumenttypelambdaexpressionisnotassignableto

c# - MethodInvoker 与 Control.BeginInvoke 的操作

哪个更正确,为什么?Control.BeginInvoke(newAction(DoSomething),null);privatevoidDoSomething(){MessageBox.Show("Whatagreatpost");}或Control.BeginInvoke((MethodInvoker)delegate{MessageBox.Show("Whatagreatpost");});我有点觉得我在做同样的事情,那么什么时候使用MethodInvokervsAction,甚至写一个lambda表达式?编辑:我知道编写lambda与Action之间并没有太大区别,但是Met

c# - Dispatcher.BeginInvoke : Cannot convert lambda to System. 委托(delegate)

我正在尝试调用System.Windows.Threading.Dispatcher.BeginInvoke。该方法的签名是这样的:BeginInvoke(Delegatemethod,paramsobject[]args)我试图向它传递一个Lambda而不是必须创建一个委托(delegate)。_dispatcher.BeginInvoke((sender)=>{DoSomething();},newobject[]{this});它给我一个编译器错误,说我can'tconvertthelambdatoaSystem.Delegate.委托(delegate)的签名以一个对象为参数,

c# - Invoke() 和 BeginInvoke() 有什么区别

只是想知道BeginInvoke()和Invoke()之间有什么区别?主要是每一个的用途。编辑:创建线程对象并对其调用调用与仅在委托(delegate)上调用BeginInvoke()之间有什么区别?还是它们是同一回事? 最佳答案 你是说Delegate.Invoke/BeginInvoke还是Control.Invoke/BeginInvoke?Delegate.Invoke:在同一线程上同步执行。Delegate.BeginInvoke:在threadpool线程上异步执行。Control.Invoke:在UI线程上执行,但调用