Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Updating ListView with Thread (+ extra thread questions)

Updating ListView with Thread (+ extra thread questions)

Scheduled Pinned Locked Moved C#
questionannouncement
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Skoder
    wrote on last edited by
    #1

    Hello, i am trying to keep updating a coloum for each ListViewItem in a ListView. I though i could just do this by a thread that kept updating every 10 secound but i can see that it is only possible to update / change / work with the ListView from the Thread that originally created it. Soo how can i achieve what i want ? Should the thread which updates the ListView instead maybe call a method like Invoke(TheMethod) every 10 seconds, or how should it be done ? Other Questions about Threads: I seem to get into 2 usuall problems. 1. I only want 1 thread to be able to be created and working on a method. I usually solve this by declaring the Thread thread globally within the class, soo before i create the Thread i check if thread == null ( create thread ), and in the code which the thread is running i then set thread == null when it exit. Is this okay ? or are there some smarter way to do it ? maybe some build in type / object or something ? 2. I only want 1 thread a time to run some code. Usually i solve this by declaring an Object threadLock globally within the class, soo i can just do lock(threadLock) { THE CODE HERE }. Any better way of doing that ? Best regards Martin :confused:

    S 1 Reply Last reply
    0
    • S Skoder

      Hello, i am trying to keep updating a coloum for each ListViewItem in a ListView. I though i could just do this by a thread that kept updating every 10 secound but i can see that it is only possible to update / change / work with the ListView from the Thread that originally created it. Soo how can i achieve what i want ? Should the thread which updates the ListView instead maybe call a method like Invoke(TheMethod) every 10 seconds, or how should it be done ? Other Questions about Threads: I seem to get into 2 usuall problems. 1. I only want 1 thread to be able to be created and working on a method. I usually solve this by declaring the Thread thread globally within the class, soo before i create the Thread i check if thread == null ( create thread ), and in the code which the thread is running i then set thread == null when it exit. Is this okay ? or are there some smarter way to do it ? maybe some build in type / object or something ? 2. I only want 1 thread a time to run some code. Usually i solve this by declaring an Object threadLock globally within the class, soo i can just do lock(threadLock) { THE CODE HERE }. Any better way of doing that ? Best regards Martin :confused:

      S Offline
      S Offline
      S Senthil Kumar
      wrote on last edited by
      #2

      Skoder wrote:

      Should the thread which updates the ListView instead maybe call a method like Invoke(TheMethod) every 10 seconds, or how should it be done ?

      That's one way to do it. If all the thread does is refresh the listview, you could use the System.Windows.Forms.Timer[^] class instead.

      Skoder wrote:

      1. I only want 1 thread to be able to be created and working on a method.

      You could use the IsAlive[^] property.

      Skoder wrote:

      2. I only want 1 thread a time to run some code. Usually i solve this by declaring an Object threadLock globally within the class, soo i can just do lock(threadLock) { THE CODE HERE }.

      That looks fine. Regards Senthil _____________________________ My Blog | My Articles | My Flickr | WinMacro

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups