Thanks Stephen

 

I have moved on to using  background (actually a  BackgroundWorker).

 

I am not sure event to use to trigger the DoWork method of the
BackgroundWorker.

I am using a button until I get it working.

 

The ProgressBar is being updated ok.

 

My problem is while it 'seems' to work ok, I cannot get the completed
FlowDocument back.

 

I have used this before (I have also set up parameterised threads) but this
seems to lend itself to my task.

 

In my DoWork Event handler I do

 

        public void DoWorkHandler(object s, DoWorkEventArgs args)
        {
            var flowDocument = new FlowDocument();
            ProcessDocument(flowDocument);
            args.Result = flowDocument;
        }

 

To get the FlowDocument I use the RunWorkerCompleted handler as such
 
        public void RunWorkerCompletedHandler(object s,
RunWorkerCompletedEventArgs args)
        {
            LogDocument = (FlowDocument) args.Result;
            this.DialogResult = true;
            this.Close();
        }
 
 
Where LogDocument is public property
 
public FlowDocument LogDocument { set; get; }
 
 
However when I try and use the built FlowDocument 
 
                    var processingDialog = new PleaseWaitDialog();
                    
                    processingDialog.Owner = parentWindow;
                    processingDialog.LogFilePath = LogFilePath + "\\" +
logFile;
                    processingDialog.IsForPrinter = false;
                    processingDialog.IntializeDialog();
                    if (processingDialog.ShowDialog() == true)
                    {
                       // Get exception here
 
logDocumentUserControl.logFlowDocumentViewer.Document =
processingDialog.LogDocument;
                    }
 
 
I get an exception
 
System.Reflection.TargetInvocationException was unhandled
  Message=An exception occurred during the operation, making the result
invalid.  Check InnerException for exception details.
 
With the inner exception
 
the calling thread cannot access this object because a different thread owns
it.
 
I used http://www.dotnetperls.com/backgroundworker as the basis for getting
objects back from my backgroundworker.
 
What should be simple, does not work.
 

Regards Peter

From: [email protected] [mailto:[email protected]] On
Behalf Of Stephen Price
Sent: Wednesday, 6 April 2011 1:18 PM
To: ozWPF
Subject: Re: WPF dialog never displayed

 

I'm guessing here but it may be possible that your loop is being done on the
UI thread thus blocking it. 

The dispatcher is supposed to take care of that but I think that's on the
assumption that your code is running on a background thread. There's no
point in using the Dispatcher if your code is already running on the UI
thread.

 

So, if that's the case (like I said I'm guessing) perhaps you could try
running it on a background thread. I've used BackgroundWorker before which
allows you to set up a a method for your Work, Progress changed, and
completed. 

 

http://msdn.microsoft.com/en-us/library/cc221403(v=vs.95).aspx

 

That would also solve your problem of doing the work without needing the
user to click a button.

 

hope that helps curb your pain. :)

cheers,

Stephen

On Wed, Apr 6, 2011 at 12:42 PM, Peter Maddin <[email protected]>
wrote:

My mistake.

 

I was using the wrong event handler to  trigger the parsing of my xml file.

However I am still having a problem with

.         How to get the dialog to start without having to have the user to
use a control (aka button) to start the file parsing.

.         The progress bar is not being updated even though I am using the
mechanism in http://www.codeproject.com/KB/WPF/WpfProgressBar.aspx to update
it.

 

I don't know why it should be this hard.

 

Regards Peter

 

From: [email protected] [mailto:[email protected]] On
Behalf Of Peter Maddin
Sent: Wednesday, 6 April 2011 11:39 AM
To: [email protected]
Subject: WPF dialog never displayed

 

I need to display a small wpf windows that shows a progress bar while
parsing an xml file and using this to add content to a flowdocument.

 

This is done from within a user control.

 

The dialog sets DialogResult to true if it works or false if an exception
occurs.

 

The dialog is working except it is never displayed.

 

What does one need to do so that it is displayed.

 

Code

 

         if (LogFilePath != null)

            {

                if (parentWindow != null)

                {

                    var processingDialog = new PleaseWaitDialog();

                    processingDialog.Owner = parentWindow;

                    processingDialog.LogFilePath = LogFilePath + "\\" +
logFile;

                    processingDialog.IsForPrinter = false;

                    processingDialog.IntializeDialog();

                    if (processingDialog.ShowDialog() == true)

                    {

 
logDocumentUserControl.logFlowDocumentViewer.Document =
processingDialog.LogDocument;

                    }

                }

            }

 

While it functions, nothing is shown.

 

Any clues as to what to do?

 

 

 

 

Regards Peter Maddin
Applications Development Officer
PathWest Laboratory Medicine WA
Phone : +618 6396 4285 <tel:%2B618%206396%204285> 
Mobile: 0414 240 307 
E-Mail : [email protected]; [email protected]
The contents of this e-mail transmission outside of the WAGHS network are
intended solely for the named recipient's), may be confidential, and may be
privileged or otherwise protected from disclosure in the public interest.
The use, reproduction, disclosure or distribution of the contents of this
e-mail transmission by any person other than the named recipient(s) is
prohibited. If you are not a named recipient please notify the sender
immediately.

 

 


_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

 

_______________________________________________
ozwpf mailing list
[email protected]
http://prdlxvm0001.codify.net/mailman/listinfo/ozwpf

Reply via email to