/* STAShowDialog takes a FileDialog and shows it on a background STA thread and returns the results. * Usage: * OpenFileDialog d = new OpenFileDialog(); * DialogResult ret = STAShowDialog(d); * if (ret == DialogResult.OK) * MessageBox.Show(d.FileName); */ public static DialogResult STAShowDialog(FileDialog dialog) { DialogState state = new DialogState(); state.dialog = dialog; System.Threading.Thread t = new System.Threading.Thread(state.ThreadProcShowDialog); t.SetApartmentState(System.Threading.ApartmentState.STA); t.Start(); t.Join(); return(state.result); }
/* STAShowDialog takes a FileDialog and shows it on a background STA thread and returns the results. * Usage: * OpenFileDialog d = new OpenFileDialog(); * DialogResult ret = STAShowDialog(d); * if (ret == DialogResult.OK) * MessageBox.Show(d.FileName); */ public static DialogResult STAShowDialog(FileDialog dialog) { DialogState state = new DialogState(); state.dialog = dialog; System.Threading.Thread t = new System.Threading.Thread(state.ThreadProcShowDialog); t.SetApartmentState(System.Threading.ApartmentState.STA); t.Start(); t.Join(); return state.result; }