среда, 24 августа 2011 г.

MessageBox display called from a separate thread

It is modal only to the windows you created in the same thread.  None, I'm sure in your case.  Just use Control.Invole() to make it modal to the UI thread.  For example:

  public partial class Form1 : Form {
    public Form1() {
    private delegate DialogResult MessageBoxDelegate(string msg, string title, MessageBoxButtons buttons, MessageBoxIcon icon);

    private void button1_Click(object sender, EventArgs e) {
    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {
      this.Invoke(new MessageBoxDelegate(ShowMessage), "waz here", "nobugz", MessageBoxButtons.OK, MessageBoxIcon.Information);
    private DialogResult ShowMessage(string msg, string title, MessageBoxButtons buttons, MessageBoxIcon icon) {
      return MessageBox.Show(this, msg, title, buttons, icon);

Комментариев нет: