Answered by:
Paint Event

Question
-
In C# I have list of mulitple states (5) that I use to driver and keep track of states and what other controls on the form are to paint or don't paint. A list element becomes marked as a Reset state when a user presses a button to remove a selected item in the list. All this works good except I need to be able to cleanup the list and remove the reset marked element(s) from the list after the form paint (and all controls on the form) event has finished so the list doen't grow with a bunch of reset event marked elements as the list contains various elements that represent 5 states which drive what is painted in the paint event handler.
Is there a way to do this cleanup and safely update the list when the forms paint event has finished and not updating.
Monday, November 22, 2010 10:21 PM
Answers
-
That would depend upon how and when the form recieves the update information.
Application.Idle means nothing is occurring. The CPU is simply waiting for something to occur during the time slice given to the process. In other words, painting is never occuring during this time frame. You are guaranteed that nothing is occuring. It is possible that your Idle time is zero.
No doubt there are other approaches. Probably better approaches. Cannot say one way or the other. Not enough info.
I still think your list might best be implemented in a class, wrapped up with its' own parts and smarts. Let the BGW use it however it needs to be used. Makes for less complicated code. Your list has ceased being a mere data store, and become a living breathing thing.
(A Car class can have a variable that represents the color, or how many seats. But, you would usually implement a class to represent the Engine and provide the Car with an instance of an Engine.)
Happy Coding.
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."Tuesday, November 23, 2010 12:23 AM
All replies
-
Sounds like your list needs to be implemented by a separate class.
It is my understanding that some game software subscribe to the Application.Idle event to perform some graphics operations. Subscribe to the event in the Main method. Be sure to unsubscribe when the application closes.
http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/87ca7168-5f8a-44e6-acbd-6a647ca7f5f3
Look for the post from Tergiver, which is marked as answer. He posted a class called GameProgram again. Brilliant!
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."Monday, November 22, 2010 11:13 PM -
The list is created in a background worker thread and contains one of states depending on what is being processed in the background worker thread that runs continually as this is polling remote nodes in an industrial system. The form is updated based on what the background worker is processing. All this works fine. All I'm trying to do is just be able to remove list elements when the paintevent for the form and it's controls is done so the list is managed correctly and doesn't grow. Orignally I had the background worker thread doing the cleanup but not knowing when the paint event was done was my concern.
Is the way Rudedog2 going to work in the case of the backgroundworker thread being the driver for items that are on the list?
Tuesday, November 23, 2010 12:08 AM -
That would depend upon how and when the form recieves the update information.
Application.Idle means nothing is occurring. The CPU is simply waiting for something to occur during the time slice given to the process. In other words, painting is never occuring during this time frame. You are guaranteed that nothing is occuring. It is possible that your Idle time is zero.
No doubt there are other approaches. Probably better approaches. Cannot say one way or the other. Not enough info.
I still think your list might best be implemented in a class, wrapped up with its' own parts and smarts. Let the BGW use it however it needs to be used. Makes for less complicated code. Your list has ceased being a mere data store, and become a living breathing thing.
(A Car class can have a variable that represents the color, or how many seats. But, you would usually implement a class to represent the Engine and provide the Car with an instance of an Engine.)
Happy Coding.
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."Tuesday, November 23, 2010 12:23 AM