BackgroundWorker can update control but not Show() Window?

3 views
Skip to first unread message

jstern81

unread,
May 13, 2008, 12:54:58 AM5/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
System:
Vista
Visual Studio 2005
C#

My goal is to check periodically for a certain condition which when
true indicates my system-tray application should make itself visible
to the user.

Problem: From my Timer, invoking the BackgroundWorker.RunWorkerAsync,
with an implemented RunWorkerCompleted method which calls Show() on
the application window, throws an InvalidOperationException: 'Cross-
thread operation not valid: Control accessed from a thread other than
the thread it was created on.'

I am able to successfully use the very same code to update a control
within the window, but I can't Show() the window to the user from the
Timer -> BackgroundWorker. Is this not possible with
BackgroundWorker? Should I be approaching this problem differently?
Any help is greatly appreciated.

Glenn

unread,
May 13, 2008, 1:02:56 PM5/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Controls can only be updated from the thread that created them. You
can allow this by setting CheckForIllegalCrossThreadCalls to false.
However, use this with caution as it may cause other problems.

...Glenn

Andrew Badera

unread,
May 13, 2008, 1:19:21 PM5/13/08
to DotNetDe...@googlegroups.com

Glenn

unread,
May 13, 2008, 1:27:06 PM5/13/08
to DotNetDevelopment, VB.NET, C# .NET, ADO.NET, ASP.NET, XML, XML Web Services,.NET Remoting
Can you?? I don't have any practical experience with delegates so I
wouldn't know.

When I get out of my specification phase and get back into my coding
phase, I'm going to look into delegates and see what I'm missing.

...Glenn
Reply all
Reply to author
Forward
0 new messages