Results 1 to 8 of 8

Thread: threading, Q2?!

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227

    threading, Q2?!

    I have a listview in my program, am i going to have any problems if 2diff thread access ( read and write ) to it at the same time?!

    if yes what to do? ( can we syncronize it somehow? )


    and another question that has to do with threading in genral , when 2 threads access the same obj, are we only gonna have problems when they both want to write to it? or problems happen both when writting and reading?


    thanks for your times again...

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256

    Re: threading, Q2?!

    Originally posted by persianboy
    I have a listview in my program, am i going to have any problems if 2diff thread access ( read and write ) to it at the same time?!

    if yes what to do? ( can we syncronize it somehow? )


    and another question that has to do with threading in genral , when 2 threads access the same obj, are we only gonna have problems when they both want to write to it? or problems happen both when writting and reading?


    thanks for your times again...
    Yes you will have problems. You have to lock the thread while you write. Use the synclock keyword.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    which thread? is there anyway to synlock the listview?!

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Whatever method access and uses the Listview should use a SyncLock block around the listview usage. Also remember that you can't create a UI object in an alternate thread and add it back into the main thread. In other words you can create a New ListViewItem in a thread other than the UI thread (main thread). There are some exceptions like using Invoke, but generally speaking.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    the listview is in the main thread. the question do i have to synclock the listview object, or the methods that try to access it?

    can you write the one line that synclock the control for me, thanks

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Synclock doesn't work like that. It takes at least three lines at least to use it. Read the help on it.
    VB Code:
    1. SyncLock listview1
    2.  'put any code to add or whetver to the listview here
    3. End SyncLock

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Sep 2003
    Posts
    227
    i changed it, thanks.

    and the question thats on the first msg of this thread still remains unanswered to me >>

    when 2 threads access the same obj, are we only gonna have problems when they both want to write to it? or problems happen both when writting and reading?

  8. #8
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339

    Re: Re: threading, Q2?!

    Originally posted by DevGrp
    Yes you will have problems. You have to lock the thread while you write. Use the synclock keyword.
    Yes and that should be on reading and writing, anytime they try to access the same object at the same time.

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