Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

manage thread to update UI Control

Status
Not open for further replies.

dpimental

Programmer
Jul 23, 2002
535
0
0
US
All, I'm working on an asp.net app.
I have (C#) pdf page validator that evaluates the number of pages in a pdf file and compares it to the number entered on a form (the form will create an xml file used to configure an order).
My problem is that the process to run the validator against a large pdf file takes long enough that I would need to run it on a separate thread; but I can't seem to update / reference controls on the main UI Thread. The last thing I tried was the following.

Code:
Task taskA = Task.Factory.StartNew(() => DoSomeWork(5000));
taskA.Wait();

I have also tried this

Code:
MainThread = SynchronizationContext.Current;
        if (MainThread == null) MainThread = new SynchronizationContext();

        MainThread.Send((object state) =>
        {
            //pdfPageStatus.Text = pdfPages.ToString() + " pages in PDF File Uploaded";
            pdfPageStatus.Text = " pages in PDF File Uploaded";
            pdfPageStatus.ForeColor = Color.Blue;
        }, null);

David Pimental
(US, Oh)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top