如何使用C#在调用方法中从线程通知异常 [英] How to notify the exception from thread in calling method using C#

查看:154
本文介绍了如何使用C#在调用方法中从线程通知异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在更新数据库和sharepoint中的一些信息。在共享点更新的详细信息需要更多时间。所以我已经为执行与sharepoint相关的东西的方法实现了线程。如果在线程中发生任何异常,我怎么能在调用地方处理它?<​​br />


我尝试了什么:



无法处理它主要方法

i'm updating some information in DB as well as in sharepoint. details updating in share point is taking more time. so i have implemented threading for the method which is doing sharepoint related stuffs. if in case of any exception occurs in threading how could i handle it in calling place?

What I have tried:

unable to handle it main method

推荐答案

这不简单,但可行。

开始查看的地方是参考资料来源:参考来源:BackgroundWorker类 [ ^ ] - 报告进度时就是这样;它在调用线程中引发了一个ProgressChanged事件。

看看它使用 asyncOperation 变量做了什么,它应该是有意义的。
It's not simple, but it is do-able.
One place to start looking is at the reference sources: Reference Source: BackgroundWorker Class[^] - it does just that when you report progress; it raises a ProgressChanged event in the calling thread.
Have a look at what it's doing with the asyncOperation variable and it should make sense.


如果您正在使用ADO并更新或插入,您可以评估受影响的记录数量值,该值是 SqlCommand 方法的结果你打电话,或者如果你在MVC应用程序中使用EF,EF中内置了一些机制,允许你处理错误。
If you're using ADO and updating or inserting, you can evaluate the number of records affected value that is the result of the SqlCommand method you called, or if you're using EF in a MVC app, there are mechanisms built into EF that allows you to handle errors.


这篇关于如何使用C#在调用方法中从线程通知异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆