Chris McElligott Park
Chris McElligott Park

Reputation: 3127

In Windows Forms, how to stop the the UI thread from blocking when the user clicks a scrollbar?

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?

Upvotes: 2

Views: 1401

Answers (4)

James Black
James Black

Reputation: 41858

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

Upvotes: 1

MusiGenesis
MusiGenesis

Reputation: 75376

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

Upvotes: 1

Beth
Beth

Reputation: 9617

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

Upvotes: 0

Mike Dinescu
Mike Dinescu

Reputation: 55760

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.

Upvotes: 3

Related Questions