Link to home
Start Free TrialLog in
Avatar of biggstrc
biggstrc

asked on

Improving UI responsiveness of a Marquee through threading

I am looking to improve the responsiveness of a UI control in a .NET project.  It is a scrolling Marquee that displays RSS feeds.  I am using the NetMarquee control from an online source.  It provides a simple control to allow scrolling text.  However, the issue is that when I perform other tasks on the UI it causes the Marquee to stutter.  This is particularly true when I load images onto the UI.  I am working to reduce the workload of the image load, but that isn't really the issue.  It is just the indicator of the issue.  The issue is that the Marquee is affected by the load on the UI.  I want to isolate the Marquee if possible.

What I would like to do is operate the Marquee entirely on its own thread.  It is a self-contained component that would not need to contact the other UI components in any way.  The reverse is true as well.  So far I have found ways to marshal calls to and from worker threads, but this does not help me.  The issue is that the control itself is getting bogged down.

Is there a way to isolate one control?  I can create it at runtime, but I have heard that you cannot create a control with a parent on a different thread.  Is there a way to get around this?

As far as .NET languages go, I can do this in VB.NET or C#, so examples in either would be helpful.  I would welcome any suggestions about how to make this control operate better.  I am using Visual Studio 2008 to create these forms.  If Visual Studio 2010 would bring new features that I could leverage, I would move ahead to that platform to accomplish this task.
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of biggstrc
biggstrc

ASKER

CodeCruiser:
I'll look into that.  It looks interesting, but it will take a bit of work to see if it will really pay out the way I want.  Thanks for the link.  I'll let you know what I find.

Idle_Mind:
Wow, that is something I had not considered.  That seems like a simple solution that might actually work out perfectly for me.  I would still like to figure out some way to run different controls on different threads for other purposes, but this seems like the solution I need for this project.  I'll try it out and let you know how it works out.

Thanks to both of you for your help in this matter.  If you have any more bright ideas before I get back to you, please let me know.
As a general rule of thumb: "All controls run in the SAME main UI thread".  =(

Translation: You can't run just one control in its own thread.

CodeCruisers post really describes how to put WORK into a different thread while correctly displaying progress on the main UI thread.
CodeCruiser:

The solution you posted seems to be optimized only when it comes to background processing.  The problem is that all of my processing has to be done on the foreground.  I am using GDI to move the crawl across the screen.  I can't put this type of code into a background thread.

Idle_Mind:
I think your solution is going to work.  I am working up a prototype now.  I got it to run, but I'm still working on how to get the window to resize, move, and close how I want it to.  You (or anyone else) wouldn't happen to have some example code (preferably in VB.NET but either will do) that shows how to do this would you?
I was able to get this to work finally.  The information from Idle_Mind really helped get me down the path.  I had to add to the solution, however, because I needed extra features (resize, close on application close, etc.) I browsed the web for a more full example.  I found this article:

http://www.codeproject.com/KB/miscctrl/AppControl.aspx

That took the SetParent() idea and made a control out of it that does just about everything I wanted it to do.  There are a couple of notes that I found were important to this setup though.  First, I wanted my sub-application (the RSS Feed) to be transparent so that it would take on the color scheme of the parent.  This works fine until you call it using the SetParent() API call.  Then it disappears entirely.  Still not sure why, but I decided not to mess with it.  I also found that it didn't like it if the sub-application didn't have a normal window around it.  There is code in the actual control that you can comment out or modify to get around this, but I decided that it was easier just to keep the normal form window since the control scrapes it off.

I appreciate all of the help.  The end result is that I have what I wanted in a working condition.  I am using a different thread for a UI component.
Further explanation on the web with examples was necessary, but this solution pointed me in the right direction.  Further clarification was also added to this discussion near the end.