"The calling thread must be STA, because many UI components require this"

Hi Experts,

   First off, I am brand new to WPF.    I have a few threads that run in the background of my WPF desktop app.  In the mean time I have a global class that subscribes to the error event of all of these different BackgroundWorker threads.  When one of these error events fire, the event handler in the global class attempt to pop-up an error form.  When that happens I get a runtime error saying: "The calling thread must be STA, because many UI components require this"  I know that what is going on is that a non-UI thread is trying to create a UI object.  My problem is that I have no idea how to fix it.  In WinForms I would have done something like:

 
if (this.InvokeRequired)
            {
                NoParameterDelegate delegateObject = new NoParameterDelegate(this.RefreshGradient);
                this.Invoke(delegateObject, new object[] { });
            }
            else
            {
               UpDateMyUI();
            }

Open in new window


Thanks!
axnst2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

axnst2Author Commented:
BTW, I am using .NET 4.0, VS2010
0
axnst2Author Commented:
No responses...

What I am trying to accomplish is a very simple thing to do in WinForms.  So it seems to me that WPF is great for very simple applications that you want to make look prety, but as soon as you try to do something besides showing a list of pictures or adding 2+2, it is absolutley useless.  Now if I could only get my boss to understand this...  It really is sad that Microsoft has decided that WPF is going to be the replacement for WinForms.  I see the technology as a step backwards not forward....  To me it seems that the technology was created to handle mindless applications that look very pretty.  Unfortunately, I need it to solve complex engineering problems and not sell makeup... PLEASE PROVE ME WRONG!
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
It's pretty similar...just use the Dispatcher() instead of the Form (this):
http://www.experts-exchange.com/Programming/Languages/C_Sharp/Q_26370867.html#33333150
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
*From the linked PAQ*

    "That doesn't solve my issue but it does provide me with a work around.  So how can I get refrence to the main window from else where?  Is there like a global or static reference to it?"

Referencing a window in WPF is no different than in WinForms.  You need to pass a reference to the form/class following standard OOP procedures...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
axnst2Author Commented:
Thanks!  I am starting to realize that with WPF I have to have a completely different mind set all together.  It's like I have to unlearn everything I know to work and learn a whole new way of looking at things...this is going to be one steeeeeeeeepppp a.. learning curve......

Thanks for your help!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.