|
-
Aug 21st, 2012, 05:31 AM
#1
Thread Starter
New Member
Problem with controls, forms and thread concurrency
Hi.
Im doing a program in vb .net 2010 that consist in various forms with custom controls in them. The main form declares a shared system timer and some variables, shared too.
When the main form loads I initiate the timer with an interval of 1 second and modify in the elapsed event some of these variables. For example I have a boolean that alternatively changes from true to false.
The thing is that i want to synchronize all the controls in the others forms with this global timer so in the Load of the control I had a handler for the elapsed event of the global timer, as it's the only way I know of how to do it.
With this I can for example make the images in all the controls blink at the same time, synchronized, thanks to the shared boolean of the main form. In the main form I modify it in the elapsed event and in each control I assign the visibility to the image based on this boolean in the elapsed handler of the global shared timer.
The problem with this, as you can imagine, is the concurrent use of the shared variables. If I read, for example, the boolean in one of the controls while it's being modified, it generates an exception.
I have been investigating trying to find how to solve this problem. I have seen about delegates, the SyncLock instruction and some other more, but I don't know how to apply them. From what I can remember of concurrent programming, I should need an exclusive lock where I modify the boolean and shared lock whenever I read that boolean, but im somewhat new in .Net and im a little lost. Does anyone has any piece of advice for me?
Thanks in advance
Regards
Last edited by Leucaruth; Aug 21st, 2012 at 06:33 AM.
Tags for this Thread
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
|