views:

120

answers:

4

No other control does this other than the scrollbars of panels, etc. Clicking and holding a button, a label, a link, a tab, whatever other control does not have this effect. But as soon as a user clicks the scrollbar, or clicks and drags the scrollbar, all other processing on the UI thread is halted. This is something that is a big problem for my application (a game, which needs to keep running in this circumstance), but I can't figure out a way to deal with this through overloads, adding in Application.DoEvents calls, or anything like that. Any thoughts?

+3  A: 

It sounds to me like you should try to move your game logic in a different thread (as opposed to having your game logic run inside of the main UI thread).

I don't think there is any way to disable the behavior of the scrollbars. Unless your create your own controls and provide your own scrolling functionality for the containers that need it.

Miky Dinescu
I've actually done that sort of thing in the past, with custom scrollbars, and that's more attractive than splitting my threads out -- but that's still a lot of work for not much benefit other than this one thing. I'm really surprised there would not be a way around this.
x4000
There's more to multi threading than may appear at first, but in the end there's probably more to your game environment as well.. so good luck!
Miky Dinescu
A: 

Or resize it so the scrollbars aren't needed, or move additional functions they'd normally scroll to to other controls (menu, button)

Beth
This is for content that can't be handled any way other than scrolling, unfortunately.
x4000
+1  A: 

Write your own scrollbars/scrollable panels. Scrollbars are the ugliest/clunkiest controls in Windows anyway (except for all the others).

MusiGenesis
Well, in the end this is what I wound up doing. I've based my work off of <a href="http://www.codeproject.com/KB/miscctrl/customscrollbar.aspx">this article</a> at CodeProject. The methods the article writer uses are a bit odd in that it keeps the real scrollbar and just masks them, but by using the Top offsets instead of the AutoScrollPosition, I'm able to get the same results as him without doing anything so hackish -- and it plays nice with the rest of the thread.
x4000
+1  A: 

As soon as you start your game get off of the main thread, and do all your business logic there, but, you will need to deal with the problem that all the winform controls can only be updated by the event thread.

You will need to use InvokeRequired on the controls before changing them.

This will help get you started: http://msdn.microsoft.com/en-us/library/ms171728%28VS.80%29.aspx

James Black
Hmm, I'm not sure if Direct3D can be run in the context of a secondary thread. The only problem caused by the main UI thread is these scrollbars, so I'm not real keen on making a huge shift to the application for this. I already have a number of threads in play (one for AI, one for networking, a number of sound/music playback), and all of them already use Invoke, etc, on the main form so that they can safely pass data to the main thread. This is very helpful, and I'm not sure I want to move to a more complex locking system for something so prosaic as scrollbars.
x4000
I am not suggesting Direct3D, but just get your application off the main thread, but whenever you go to update a component you will first need to see if that event call to update is on the main thread. If it isn't then you call the Invoke command to get onto the main thread, and update the control. Ideally your application shouldn't run on the main thread, it will cause more problems, potentially, down the road.
James Black
No -- what I'm saying is, this is already a Direct3D application. In other words, it is a mix of GDI and Direct3D, so I can't move my application logic off the main thread. The application is already in a production environment with several thousand users, it's doing just fine except for this one thing...
x4000
Oh, I see. I never mixed GDI and Direct3D. When I use the latter I do everything in it. Creating your own scrollbar/scrollpane may be your best bet then.
James Black