|
-
Apr 24th, 2014, 03:18 AM
#1
-
Apr 24th, 2014, 03:52 AM
#2
Re: Seeking advice regarding seperation GUI from calculation
You're missing something. You simply have the background calculation keep a track of areas that need invalidating, and have the UI thread access that and only invalidate those regions.
-
Apr 24th, 2014, 06:12 AM
#3
Re: Seeking advice regarding seperation GUI from calculation
OK, thanks.
I do have a further question on your suggestion:
In can calculate the regions that need to be invalidated on the BackGroundThread, however how would you hand that over to the UI thread. Save all the regions in a global Variable, report progress and in the .ProgressChanged Event use that Variable the hand the regions to the GUI??
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Apr 24th, 2014, 08:27 AM
#4
Re: Seeking advice regarding seperation GUI from calculation
It would depend to a certain extent how you are handling your threading. I had assumed you were starting a new Thread to run your game loop when I read your initial description, but it sounds more like you've gone for a BackgroundWorker. In which case, yes you could try stuffing the data across in the ReportProgress event. However, I'd suggest trying for a different approach. Have a single ConcurrentQueue(Of Rectangle) which the background thread can Enqueue rectangles that need invalidating onto, and the UI thread can TryDequeue from. There is no issue with both the background thread and the UI thread handling the rectangles, because they are not UI controls and aren't owned by a thread. Once the background thread has written them to the queue it doesn't touch them again so there is no issue with mutating state (Rectangles may even be immutable?). The queue needn't be stored globally either, both the UI thread and the background thread can be quite happy with a local reference.
How are you signalling to the UI thread that it needs updating? Presumably a ReportProgress call? That can trigger the UI thread pulling the Rectangles and invalidating those that need to be done no problem.
-
Apr 24th, 2014, 09:21 AM
#5
Re: Seeking advice regarding seperation GUI from calculation
Many thanks, I'll give Queue a try
Excuse me for not telling that I'm using Backgroundworkers.
This one will keep me busy for while, since I will encounter some cross thread problems (I started this thing when I joined in here, so I have to untangle a lot,
Topic is solved for me.
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|