This is typically how I ensure the method is executed back on UI thread. Typically it would not be a button click but an event handler...
You might want to look into Synchronizing context for your library classes that run on seperate thread. You can assign the UI thread as the synchronizing context and inside your non-ui thread you can post back to the UI thread so any events raised or methods executed can be executed back to the UI thread if you are required to update UI controls.
Understanding SynchronizationContext (Part I)[
^]
http://www.codeproject.com/search.aspx?q=Synchronizing+context&sbo=kw&x=0&y=0[
^]
private void button1_Click(object sender, EventArgs e)
{
if (this.InvokeRequired)
{
this.Invoke(new EventHandler(button1_Click), new[] { sender, e });
}
else
{
}
}