0
private static void runantc_OutputDataReceived(object sendingProcess, DataReceivedEventArgs outLine)  
        {
            // Collect the sort command output.
            if (!String.IsNullOrEmpty(outLine.Data))
            {
                ProcoutputTextBlock.Dispatcher.BeginInvoke(new Action(() => { ProcoutputTextBlock.Text += outLine.Data; }, null));
            }
        }

Hi, in the above code i am having errors @ProcoutputTextBlock Error 1 An object reference is required for the non-static field, method, or property 'WpfApplication1.Window1.ProcoutputTextBlock'

and @ () => { ProcoutputTextBlock.Text += outLine.Data; }, null Error 2 Method name expected

can anybody enlighten me?

2 Answers 2

2

Your function is static, which means that it requires a reference to an instance of the class in order to access any instance members. Since I'm assuming that ProcoutputTextBlock is a TextBlock on your window, it needs an instance in order to access it.

The other option is making the function non-static, but since you don't show how this event handler is being attached, I don't know if that's a viable option for you.

Sign up to request clarification or add additional context in comments.

Comments

1

ProcoutputTextBlock is an instance property. You are accessing instance property from static method runantc_OutputDataReceived.

To resolve this remove static from runantc_OutputDataReceived declaration.

To fix the second issue, remove the second argument null. Like this:

ProcoutputTextBlock.Dispatcher.BeginInvoke(new Action(() => { ProcoutputTextBlock.Text += outLine.Data; }));

or

ProcoutputTextBlock.Dispatcher.BeginInvoke((Action)(() => { ProcoutputTextBlock.Text += outLine.Data; }));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.