First of all, the design you are trying to implement is pretty ugly, but I could only advise you something better if I knew your ultimate design goals. But the problem is simple; you don't need any additional thread, no unsafe code nothing. Your suggestion to use
Form.Shown
is correct, and your idea that it can block anything is just a misconception. But perhaps you don't know what a dialog is.
A custom dialog is the same as the form, only it is shown using
Form.ShowDialog
. Then, during the modal state of it, you cannot select any other form of the same application. If you do need to access other forms, it should be
Show
instead. The simplest code I could think of would be all in the entry-point method, provided you already have two form types. It can look like this:
using System;
using System.Windows.Forms;
[STAThread]
static void Main() {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var mainForm = new FormMain();
mainForm.Shown += (sender, eventArgs) => {
new FormDialog().ShowDialog();
};
Application.Run(mainForm);
}
—SA