using System;
using System.Windows.Forms;
using System.ComponentModel;
namespace AsyncWorkerCs {
public partial class uclExceptions : UserControl {
private Action<string> _ThrowEx = delegate(string text) { throw new Exception(text); };
public uclExceptions() { InitializeComponent(); }
private void btBackgroundworker_Click(object sender, EventArgs e) {
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {
_ThrowEx("thrown by backgroundWorker1");
}
private void btWithoutEndInvoke_Click(object sender, EventArgs e) {
_ThrowEx.BeginInvoke("thrown without EndInvoke", null, null);
}
private void btWithEndInvoke_Click(object sender, EventArgs e) {
_ThrowEx.BeginInvoke("thrown with EndInvoke", _ThrowEx.EndInvoke, null);
}
private void btAsyncworker_Click(object sender, EventArgs e) {
_ThrowEx.RunAsync("thrown by Asyncworker");
}
private void btSynchron_Click(object sender, EventArgs e) {
_ThrowEx("thrown in main-thread");
}
}
}