草庐IT

invoke_result

全部标签

c# - Control.Invoke 输入参数

根据我在C#中的发现,Control.Invoke方法要求您使用不带输入参数的委托(delegate)。有没有办法解决?我想调用一个方法来从另一个线程更新UI并将字符串参数传递给它。 最佳答案 您使用的是哪个版本的C#?如果您使用的是C#3.5,则可以使用闭包来避免传入参数。使用C#3.5publicstaticclassControlExtensions{publicstaticTResultInvokeEx(thisTControlcontrol,Funcfunc)whereTControl:Control{returncont

C# if 语句速记运算符 (?:) results in unreachable code

为什么我在使用VisualStudio2010的C#中收到此警告?"Unreachableexpressioncodedetected"来自以下代码(DateTime.Now以绿色波浪线下划线):publicDateTimeStartDate{get{DateTimedt=(DateTime)ViewState["StartDate"];return((dt==null)?DateTime.Now:dt);}} 最佳答案 因为DateTime结构永远不能为null。如果您期望可能的空值,则必须使用可为空的DateTime结构。您也可

c# - 参数计数与 Invoke 不匹配?

下面的代码块导致错误:用户代码未处理TargetParameterCountException。参数计数不匹配。publicvoidAddListViewItem(string[]Data){if(InvokeRequired){Invoke(newAction(AddListViewItem),Data);}else{ListViewData.Items.Add(Data[0]).SubItems.AddRange(newstring[]{Data[1],Data[2],Data[3],});}}有什么想法吗? 最佳答案 错误是由

c# - 如果在单独的方法中调用,为什么 Parallel.Invoke 会快得多?

我执行了3次QuickSort-Algorithm并测量了对5000万个随机数进行排序的时间:顺序(大约需要14秒)使用Parallel.Invoke()作为排序算法的相同方法(耗时约12秒)使用Parallel.Invoke()在单独的方法中(耗时约7秒)所以我的问题是:如果在单独的方法中调用,为什么Parallel.Invoke()会快得多?在我的电脑上,示例3.的速度是示例2的两倍多。2。使用Parallel.Invoke()作为排序算法的相同方法publicclassParallelQuickSort{privateconstintThreshold=100;publicsta

c# - 是否应该重写所有接口(interface)以返回 Task<Result>?

我有一个简单的界面publicinterfaceSomethingProvider{publicSomethingGetSomething();}为了“使”它异步,我会这样做publicinterfaceSomethingProvider{publicTaskGetSomethingAsync();}虽然接口(interface)现在暗示GetSomething是异步的,但它允许同步执行,如果同步结果足够快,这很好。如果它阻塞,那么我可以将责任归咎于实现程序员对接口(interface)的不良实现。因此,如果后一个接口(interface)由足够快的阻塞实现来实现,则后一个接口(int

c# - 带有参数的 Dispatch.Invoke( new Action...)

以前我有Dispatcher.Invoke(newAction(()=>colorManager.Update()));从另一个线程更新显示到WPF。由于设计原因,我不得不更改程序,并且我必须将ColorImageFrame参数传递到我的ColorStreamManager.Update()方法中。正在关注this链接,我将调度程序修改为:Dispatcher.Invoke(newAction((p,v)=>p.Update(v)));它编译正常,但根本无法运行。VS2010说“参数计数不匹配。”在我的ColorStreamManager.Update()方法中我有RaisePrope

c# - MethodInfo.Invoke 性能问题

我正在从一个文件中读取和写入数据。文件中的数据可以是float、double、整数等。直到运行时才知道类型。我将文件中存储的数据类型称为Tin。数据从Tout类型的数组中读取或写入。这种类型在运行时也是未知的。代码序列是这样的。在已知Tin和Tout的Open方法中,我们可以为已知数据类型创建读写方法。Open(...){MethodInfoReadMethod=typeof(...)GetMethod("ReadGeneric").MakeGenericMethod(newType[]{typeof(Tin),typeof(Tout)}));}读写循环重复数百万次并依靠反射来调用适当

c# - 使用 Moq 模拟 Delegate.Invoke() 在 LINQ 中抛出 InvalidCast 异常

假设我有IService界面:publicinterfaceIService{stringName{get;set;}}还有一个委托(delegate)Func返回此接口(interface)。在我的单元测试中,我想模拟委托(delegate)的Invoke()像这样使用Moq的方法:[TestMethod]publicvoidUnitTest(){varmockService=newMock();varmockDelegate=newMock>();mockDelegate.Setup(x=>x.Invoke()).Returns(mockService.Object);//Ther

时间:2018-01-08 标签:c#linq: how to retrieve a single result

对linq有点陌生,使用linq检索单个结果的最简单方法是什么?例子,我的查询varquery=fromcindb.productInfowherec.flavor=="ClassicCoke"&&c.container=="Can"selectc.co2Target;它应该只返回一个具有double值的字段。我如何将其从查询中拉出来?过去我使用过ExecuteScalar。我如何用linq做到这一点?我想保留它的数据类型更新:这就是我现在的位置。问题是我在这里运行的测试查询返回4而不是3.75varquery=(fromaindb.LUT_ProductInfoswherea.fla

javascript - Aurelia get value conventer results in View

我想获得在我的View中过滤数组的值转换器的结果,以便显示找到的结果数。我既不想将此逻辑移至我的Controller(以保持其清洁),也不想添加诸如从值Controller返回一些数据之类的辅助手段。我想要的:所以,基本上我想要像angularoffers这样的东西:如图所示here:ng-repeat="iteminfilteredItems=(items|filter:keyword)"或here:ng-repeat="iteminitems|filter:keywordasfilteredItems"我得到的:不幸的是,在Aurelia:doffilteredDocuments=