Thank you for your hint. The BindAsync
seems to be a useful method. We will probably add it.
In the meantime you can use one of asynchronous pattern such as:
BackgroundWorker:
BackgroundWorker worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
worker.RunWorkerAsync(new Telnet("server"));
void worker_DoWork(object sender, DoWorkEventArgs e)
{
terminal.Bind((Telnet)e.Argument);
}
void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
MessageBox.Show(e.Error.ToString());
}
Task in .NET 4.0:
Task task = new Task(() => terminal.Bind(new Telnet("server")));
task.ContinueWith((t) =>
{
if (t.IsFaulted)
MessageBox.Show(t.Exception.ToString());
});
task.Start();
Task in .NET 4.5:
await Task.Run(() => terminal.Bind(new Telnet("server"))).ContinueWith((t) =>
{
if (t.IsFaulted)
MessageBox.Show(t.Exception.ToString());
});