草庐IT

dispatch_cancel

全部标签

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# - BackgroundWorker RunWorkerCompletedEventArgs.Cancelled 始终为 false

我通过调用BackgroundWorker上的CancelAsync()方法取消我的操作,当执行落入事件RunWorkerCompleted时,属性CancelledRunWorkerCompletedEventArgs为假。不过,我不太清楚应该在何时何地将其设置为true,如EventArgs属性中所示。那么,如何呢? 最佳答案 来自MSDN:TheCancelledpropertyofRunWorkerCompletedEventArgsindicateswhetheracancellationrequestwasprocess

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

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

c# - ASP.NET WebAPI : Aborted (cancelled) requests

对于初学者来说,这是一个讨论,如果你们中的任何人在WebAPIController(可能也适用于MVC)中做请求取消这样的事情。我的意思特别是像下面这样的场景:客户端(通常是浏览器)启动请求,导航离开或更一般地,出于任何原因中止请求。现在,请求在客户端中止,不再考虑。但在服务器端,请求仍在执行,通常可能会做两件特别有趣的事情:进行(重)数据库查询对另一个服务进行(重)服务调用最后一切都白费了(至少当它是一个无副作用的读取操作时)。在这种情况下,是否有人处理取消正在进行的查询/服务调用?我所知道的是,可以在APIController中传递CancellationToken(尽管我无法让它

c# - CancellationToken Cancel 不脱离 BlockingCollection

我有一个这样的取消标记staticCancellationTokenSourceTokenSource=newCancellationTokenSource();我有一个像这样的阻塞集合BlockingCollectionitems=newBlockingCollection();varitem=items.Take(TokenSource.Token);if(TokenSource.CancelPending)return;当我打电话TokenSource.Cancel();Take没有像它应该的那样继续。如果我将TryTake与民意调查一起使用,token会显示它被设置为已取消。

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

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

c# - Dispatcher线程和UI线程有什么区别

UI线程和Dispatcher线程在WPF中是一样的还是有什么区别? 最佳答案 ADispatcher负责管理线程的工作。UI线程是渲染UI的线程。TheUIthreadqueuesworkitemsinsideanobjectcalledaDispatcher.TheDispatcherselectsworkitemsonaprioritybasisandrunseachonetocompletion.EveryUIthreadmusthaveatleastoneDispatcher,andeachDispatchercanexe

c# - ServerConnection.Cancel 方法

SqlCommand类有一个Cancel根据文档,该方法允许取消命令。我正在寻找通过smoServerclass执行的命令的等效方法.ServerConnection类(服务器类的connectioncontext字段)hasaCancelmethod但文档并不清楚它的作用。 最佳答案 SeverConnection.Cancel()方法与SqlCommand.Cancel()方法和Documentation的工作方式类似状态:Ifthereisnothingtocancel,nothingoccurs.However,ifther