This is the error I am receiving. I have a button on a winforms control (as depicted below). I have an async void method that is attached to the click event handler (as depicted below)
The issue that I am having is that this code runs perfectly fine when I first load in this form, I can click the button 1,000+ times and there is no cross threading errors that occur.
The ONLY time that I get this error is when I do the following
- hide the form
form.Hide()
(with keeping a reference to the form) - show the form for a second time
form.ShowDialog()
- click the refresh button
It seems like all of the buttons on the form will then have some sort of cross-threading issue when calling into UI controls from async method calls. It is almost as if hiding and then re-showing the dialog does something to make new controls on a new thread BUT it never calls the Initialize method again.
Does anyone know why I am having an issue?
EDIT This is also a VSTO excel addin project. The form is getting created by a ribbon button click and I hold on to a reference of the form in the ribbon class to re-show it