We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Causing events to fire

Does anyone know how to cause events for controls to fire without using the UI? I'm trying to write some unit tests for my winforms, making sure they do the correct things, but I don't know how to make the event fire generally. There is a PerformClick function on menu items and buttons which works for these cases, but I'm looking for something a bit more general. Also, I'm having a problem with PerformClick as well. It seems the event processing is synchronous here, so if my event handler calls ShowDialog on a form, then the dialog appears and the test waits until the dialog is closed. What I'd like to do is have the dialog get started on a different thread (which would also have the message pump) so my test thread could then find the dialog form and manipulate it then close it. Does anyone know of a way to do this?

Loader.
Up arrow icon