English 中文(简体)
。 NET 背景工作人员——没有办法允许例外通常回馈主线?
原标题:.NET Backgroundworker - Is there no way to let exceptions pass back normally to main thread?

问题:使用 NET 背景工作人员,没有办法让例外情况通常回馈到主线?

BACKGROUND:

  • Currently in my WinForms application I have generic exception handle that goes along the lines of, if (a) a custom app exception then present to user, but don t exit program, and (b) if other exception then present and then exit application
  • The above is nice as I can just throw the appropriate exception anywhere in the application and the presentation/handling is handled generically
最佳回答

<代码>BackgroundWorker自动冲抵该例外情况。 载于AsyncCompletedEventArgs.Error。 页: 1 工作会议活动。

如果你愿意的话,你可以总结一下并重述这次活动的例外情况,同时铭记,在造成“外包”例外情况的框架内,将会出现“排外”例外情形,而不是因为你在“<>中文本”中重述。 Invoke 。

在网申请中,在背景基础上出现的一个例外是,可以而且将会缩小整个过程的灾难性错误;处理这一问题的惟一途径是将所有活动归结在一个试捕组中,并排除出现的任何例外,即“打地工人

问题回答

如果DoWorks所呼吁的同步方法有例外,这种例外将提供给RonWorkerComple的手稿人。 你可以在那里处理。

private void backgroundWorker1_RunWorkerCompleted(
    object sender, RunWorkerCompletedEventArgs e)
{
    // First, handle the case where an exception was thrown.
    if (e.Error != null)
    {
        MessageBox.Show(e.Error.Message);
    }
    ...
}

http://msdn.microsoft.com/en-us/library/system.componentmodel.asynccompletedeventargs.error.aspx”rel=“nofollow noreferer” MSDN:

If an exception is raised during an asynchronous operation, the class will assign the exception to the Error property. The client application s event-handler delegate should check the Error property before accessing any properties in a class derived from AsyncCompletedEventArgs; otherwise, the property will raise a TargetInvocationException with its InnerException property holding a reference to Error.

无。

相反,如果贵国没有<编码>null,则你可以选择一个等级,即:,以核对<代码>e.Error,如果是<代码>null<>/code>,则可以选择一个等级。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签