Question

I'm sorry, I have no idea how to title this question.

I've written an explanation for this error about 10 times and then delete it as it isn't clear - forgive me, I'm jumping straight into the code and then will explain

public MainWindow()
    {
        InitializeComponent();
        stuff();
    }

    private void stuff()
    {
            DispatcherOperation disOp = Dispatcher.BeginInvoke(DispatcherPriority.Loaded, new Action(delegate
                {
                    //PrintDialog dialog = new PrintDialog();
                    //dialog.PrintVisual(canvas1, "");
                }));

            string x = disOp.Status.ToString();
            MessageBox.Show(disOp.Status.ToString());
    }

I have stepped through this code (F11 in Visual Studio) and when it hits the line disOp.Status.ToString() the next F11 jumps to the next line as expected.

However, when I get to the line MessageBox.Show(disOp.Status.ToString()); and press F11, it jumps to my DispatcherOperation delegate.

My question is why does this happen when I use the Messagebox control but not the string!?

(This is actually the EXACT behavior I require, but I don't want a messagebox to appear since the user has to click the OK / Cancel... How else can I replicate this?)

Thank you

Dave

Was it helpful?

Solution

BeginInvoke wont get to actually run your action until the current thread is free to process pending msgs, and MessageBox must be pumping to allow messages to get processed (kind of like DoEvents).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top