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
  1. Home
  2. General Programming
  3. C#
  4. MultiThreading\Design Question

MultiThreading\Design Question

Scheduled Pinned Locked Moved C#
designquestiondatabasecomperformance
3 Posts 3 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.
  • D Offline
    D Offline
    DavidBoyd
    wrote on last edited by
    #1

    Hi! This is what i have so far... foreach (string result in Ldap.Query(filtertext)) { ThreadStart starter = delegate { NetInfo.Resolve(result, out ipResult); }; Thread t = new Thread(starter); t.Start(); while (t.ThreadState.ToString() == "Running") { Thread.Sleep(50); } } The problem in my mind is that i'm making the UI thread sleep... this ties up the UI and seeing as how i started trying to integrate multi-threading to stop something like this and increase the speed at which i can ping other machine's and return there address assuming they are up. What should i do because i need alot of the values off the UI and i'd still like to not tie up the UI i've been reading a bit about using a threadpool i'm not sure if that would be faster or not... The other problem that i'm running into is that i have to pull a bunch of values off the form and then obviously i need to put other values back on the form in a listview. I was thinking that i could start a new thread that starts all the threads that pulls all the values back and then stores them into something like a arraylist and pushes the values back to the form... is this a good idea? or should i just forget about multi threading? I hope this isn't to muddled up and is clear enough for people to understand if you need further clarification lemme know... :) I know the human being and fish can coexist peacefully. -George Dubya Bush Don't believe me? http://politicalhumor.about.com/library/blbushism-fish.htm Yes thats right he actually said that...

    R E 2 Replies Last reply
    0
    • D DavidBoyd

      Hi! This is what i have so far... foreach (string result in Ldap.Query(filtertext)) { ThreadStart starter = delegate { NetInfo.Resolve(result, out ipResult); }; Thread t = new Thread(starter); t.Start(); while (t.ThreadState.ToString() == "Running") { Thread.Sleep(50); } } The problem in my mind is that i'm making the UI thread sleep... this ties up the UI and seeing as how i started trying to integrate multi-threading to stop something like this and increase the speed at which i can ping other machine's and return there address assuming they are up. What should i do because i need alot of the values off the UI and i'd still like to not tie up the UI i've been reading a bit about using a threadpool i'm not sure if that would be faster or not... The other problem that i'm running into is that i have to pull a bunch of values off the form and then obviously i need to put other values back on the form in a listview. I was thinking that i could start a new thread that starts all the threads that pulls all the values back and then stores them into something like a arraylist and pushes the values back to the form... is this a good idea? or should i just forget about multi threading? I hope this isn't to muddled up and is clear enough for people to understand if you need further clarification lemme know... :) I know the human being and fish can coexist peacefully. -George Dubya Bush Don't believe me? http://politicalhumor.about.com/library/blbushism-fish.htm Yes thats right he actually said that...

      R Offline
      R Offline
      RichardM1
      wrote on last edited by
      #2

      I agree that "Thread.Sleep(50);" is sleeping the UI thread. Bad thing to do, generally speaking. You might want to change the while(t.ThreadState.ToString() == "Running"){} into while(t.ThreadState == ThreadState.Running){} Strings are slower, and string compare should be done using String.Compare(string a, string b), not a == b, which does not compare the string content. There are a number of mechanisms for sharing data between the UI and other threads. A simple one is to have the thread Invoke a call on the form. This will allow the other thread to pass data back to the form with out UI sync problems. You also need to pass the initial data in to the thread you are starting. Generally, I create a class that has the threaded method, and holds the data (or references) that are needed. The UI thread creates objects of that class, hands them the data, and tells them to go start themselves. That way you just start them,and don't have to wait for any type of sync events before you start the next. LMK if that helps.

      Learn to write self marginalizing code! Call 1-888-BAD-CODE ------------------ Silver member by constant and unflinching longevity.

      1 Reply Last reply
      0
      • D DavidBoyd

        Hi! This is what i have so far... foreach (string result in Ldap.Query(filtertext)) { ThreadStart starter = delegate { NetInfo.Resolve(result, out ipResult); }; Thread t = new Thread(starter); t.Start(); while (t.ThreadState.ToString() == "Running") { Thread.Sleep(50); } } The problem in my mind is that i'm making the UI thread sleep... this ties up the UI and seeing as how i started trying to integrate multi-threading to stop something like this and increase the speed at which i can ping other machine's and return there address assuming they are up. What should i do because i need alot of the values off the UI and i'd still like to not tie up the UI i've been reading a bit about using a threadpool i'm not sure if that would be faster or not... The other problem that i'm running into is that i have to pull a bunch of values off the form and then obviously i need to put other values back on the form in a listview. I was thinking that i could start a new thread that starts all the threads that pulls all the values back and then stores them into something like a arraylist and pushes the values back to the form... is this a good idea? or should i just forget about multi threading? I hope this isn't to muddled up and is clear enough for people to understand if you need further clarification lemme know... :) I know the human being and fish can coexist peacefully. -George Dubya Bush Don't believe me? http://politicalhumor.about.com/library/blbushism-fish.htm Yes thats right he actually said that...

        E Offline
        E Offline
        engsrini
        wrote on last edited by
        #3

        Hi, For more responsive UI in case of multithreading, think about BackgroundWorker class. The class is providing options to intimate the UI about the progress of the thread and thread completion status. Please lemme know if it works.

        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