Dispatcher CheckAccess 的用途是什么?
在完成事件的异步 Web 服务上,有一个代码,例如:
Debug.Assert(Dispatcher.CheckAccess()); // don't do marshaling here- it's already runinng on UI thread!
有人知道如果我删除此代码会发生什么吗? 或者,能回答我的问题吗?
On Async webservice on complete event, there is a code such as:
Debug.Assert(Dispatcher.CheckAccess()); // don't do marshaling here- it's already runinng on UI thread!
Does anybody know what happens if I remove this code?
Or, able answer my questions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个调试断言。删除它不会对生产代码产生任何影响。
不过,它正在做的是使用 Dispatcher.CheckAccess () 来验证此时执行期间您是否位于 UI 线程上。如果从后台线程调用该方法,断言将会失败。
删除它可能会影响您将来调试它的能力。
That's a debugging assertion. Removing it will have no effect on production code.
What it's doing, though, is using Dispatcher.CheckAccess() to verify that you are on the UI thread during the exectution at that point. If you call that method from a background thread, the assertion will fail.
Removing this may have an impact on your ability to debug that in the future.