草庐IT

dispatch-after

全部标签

c# - Dispatcher.Invoke with anonymous delegate 在 Silverlight 中有效但在 WPF 中无效

在Silverlight4中,我有一个自定义服务类,它有一个异步的Completed事件。在Completed事件中,我获取返回的数据并通过如下方式调用填充方法:privatevoidservice_Completed(objectsender,CompletedEventArgsargs){Dispatcher.BeginInvoke(()=>populateInbox(args.Jobs));}privatevoidpopulateInbox(Listjobs){inbox.DataContext=jobs;}BeginInvoke在SL4中工作,但是当我将它移植到WPF时,出现以

c# - 为什么每个 Dispatcher.BeginInvoke 回调都有一个唯一的同步上下文?

我刚刚注意到,在.NET4.5中,每个Dispatcher.BeginInvoke/InvokeAsync回调都在其自己非常独特的同步上下文(的实例)上执行DispatcherSynchronizationContext).这种变化背后的原因是什么?以下简单的WPF应用说明了这一点:usingSystem;usingSystem.Diagnostics;usingSystem.Threading;usingSystem.Windows;usingSystem.Windows.Threading;namespaceWpfApplication{publicpartialclassMain

c# - Dispatcher.BeginInvoke 问题

对于此代码,我收到“非静态字段、方法或属性‘System.Windows.Threading.Dispatcher.BeginInvoke(System.Action)’需要对象引用”。privatevoidResponseCompleted(IAsyncResultresult){HttpWebRequestrequest=result.AsyncStateasHttpWebRequest;HttpWebResponseresponse=request.EndGetResponse(result)asHttpWebResponse;using(StreamReadersr=newSt

c# - WPF Dispatcher BeginInvoke 排序保证

如果我打电话Dispatcher.BeginInvoke(operation,DispatcherPriority.Loaded)来自20多个线程的1,000,000次,这1,000,000次操作是否保证按BeginInvoke调用的顺序由UI线程执行? 最佳答案 msdn说IfmultipleBeginInvokecallsaremadeatthesameDispatcherPriority,theywillbeexecutedintheorderthecallsweremade但是如果您从多个线程访问Dispatcher那么An

c# - 奇怪的 "Collection was modified after the enumerator was instantiated"异常

也许有人可以为我指出正确的方向,因为我对此一头雾水。我有一个函数可以简单地打印出类的LinkedList:LinkedListcomponents=newLinkedList();...privatevoidPrintComponentList(){Console.WriteLine("---ComponentList:"+components.Count+"entries---");foreach(Componentcincomponents){Console.WriteLine(c);}Console.WriteLine("------");}Component对象实际上有一个自定

c# - MVC 4 : How to maintain sessions and cookies to be still valid after IIS restart?

似乎我的登录session(使用简单成员资格)和cookie(验证token)在IIS服务器重新启动后无效。这对我来说是个问题,如果用户在交易中间然后服务器重新启动,用户必须重新填写表格并重新填写,当交易在中间中断时也可能是一些代码问题过程。如何让它们在服务器重启后仍然有效?这是我的web.config:.........更新我尝试使用SQLServer来存储session状态。然后出现新问题,我不能使用ViewBag,因为它不是Serializable。还有其他方法可以实现吗? 最佳答案 没有办法实现这个AFAIK。您始终可以使用

c# - Visual Studio : Automatically insert a space after typing if(

我们有一个代码风格检查器,它在每次checkin之前运行,要求C#if语句的格式如下:if(condition)但是,我的肌肉内存力已经可以打字了:if(condition)有什么方法可以让VisualStudio2010在我键入没有空格的情况下自动插入该空格?我知道你可以设置它,当你粘贴代码时,它会自动执行此操作,但不会在键入时自动执行。谢谢! 最佳答案 工具>选项>文本编辑器>C#>格式化>间距然后选中/勾选Insertspaceafterkeywordsincontrolflowstatements,它列在Setothersp

c# - Entity Framework : Invalid Column after removing the column

我在EntityFramework中映射了一个表,它非常适合添加/更新和删除记录。我从SQL服务器中删除了一个名为“Category”的列,然后在模型中重新映射了我的实体。这工作正常,该列消失了。现在,我在表上运行查询以更新一行并得到相同的错误,列“类别”无效。这已经从SQL表中删除并从实体中删除,所以当我运行以下代码时它还在寻找这个该死的列吗??using(Entitiesdb=newEntities()){varVoucher=(fromvouchersindb.Voucherswherevouchers.ID==IDselectvouchers).FirstOrDefault()

c# - Dispatcher.BeginInvoke ,尝试使用 lambda 从文本 block 获取字符串集,但出现转换错误

我试图从按钮调用选定的列表框项目,而不是wpf中的listbox.selecteditemchanged方法。所以当我尝试stringyadda=listbox.SelectedItem.ToString();我得到一个异常(exception):Thecallingthreadcannotaccessthisobjectbecauseadifferentthreadownsit.所以,我想做的是:Dispatcher.BeginInvoke(()=>{lbxSelectedItem=(lbxFileList.SelectedItemasTextBlock).Text;});这也不起作

c# - 正确使用(或不使用)Dispatcher.CheckAccess()

在Winforms中,所有控件都有一个InvokeRequired属性,如果我必须调用.[Begin]Invoke控件以修改它,它会返回true。在WPF中,DispatcherObject.CheckAccess()和Dispatcher.CheckAccess()中有一个明显相似的构造,但我被EditorBrowsable(EditorBrowsableState.Never)属性。当我禁用这样的编辑器浏览时,我用它来表示“你不应该不这样做。不,真的。如果这需要解决你眼前的问题,你错误地设计了你的解决方案首要问题。”另一方面,我发现的唯一替代方案(事实上,也是我最初的解决方案)是T