Results 1 to 2 of 2

Thread: [2005] Getting and Setting a Property at the same time

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 2005
    Posts
    1,521

    [2005] Getting and Setting a Property at the same time

    I am wondering if any one knows what would happen, if I get a property at the same time it is being set. This application that I am working on we get this random error that happens anywhere from 2 - 48 hours of it running. The only error we get says that something crash in MsCorWks.dll (this is the .Net runtime). I think I have narrowed it down to one spot where it is possible that I am getting a property at the same time it is being set from a different thread.

    So does anyone know what would happen if a property is set at the same time it it be retreived? Is there something built in that wouldn't allow this? Educated guesses welcome.
    Visual Studio Team Edition 2005
    GDI+ Links: Bob Powell VB.Net Heaven
    API Links: All API Pinvoke.Net
    VB6 to VB.Net: Visual Basic 6 to .NET Function Equivalents (Thread)

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Getting and Setting a Property at the same time

    If the same data is being accessed by multiple threads simultaneously then the result is likely to be unpredictable, because you have no idea what state the first thread left things in before the second thread stepped in. Remember that each thread is being executed one line of MSIL at a time, not one line of VB at a time. Each of your lines of VB code may be many lines of IL code. The simple answer to this is to not let it happen by using proper thread synchronisation. SyncLock blocks are the easiest way to do this. If they don't cut it then the next step up is the Monitor class. I've only ever used SyncLock so I'm no expert but if you're having thread synchronisation issues then you should follow the Articles -> Advanced .NET link in my signature and read the Managed Threading section.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width