colegas concurrentes.Excepción de trampa desde el hilo de fondo
Necesito poder atrapar una excepción que pueda arrojarse desde un hilo de fondo.
Vamos el código hable por sí misma (que es un mal código)
public delegate bool CheckForUpdatesHandler(Uri uri);
public class UpdatesChecker {
public event AsyncCompletedEventHandler CheckForUpdatesAsyncCompleted;
protected virtual void OnCheckForUpdatesAsyncCompleted(AsyncCompletedEventArgs args) {
if (CheckForUpdatesAsyncCompleted != null)
CheckForUpdatesAsyncCompleted(this, args);
}
public bool CheckForUpdates(Uri ftp) {
Thread.Sleep(1000);
throw new Exception("bla");
return true;
}
public void CheckForUpdatesAsync(Uri ftp){
var action = new CheckForUpdatesHandler(CheckForUpdates);
var c=action.BeginInvoke(ftp, delegate(IAsyncResult state) {
OnCheckForUpdatesAsyncCompleted(new AsyncCompletedEventArgs(null, false, null));
}, null);
}
}
Gracias, Marc, me has ayudado de nuevo :-) – Valentin