question in c# multi-threading

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RiskyHunter
    New Member
    • Mar 2007
    • 29

    question in c# multi-threading

    Hi all;

    I hope u don't ignore my question this time because whenever I ask questions
    here nobody answer them T_T. what's the problem is they are too trivial in away
    you don’t even want to answer them?? I really don’t know O_o

    Anyway this is my problem;

    i have a method which generate the user location;

    and i wanna use multi threading to get the position of the user concurrently;

    Hashtable ht = new Hashtable();

    public void XYZ(List<User> p2)
    {
    for (int i = 0; i < p2.Count();i++ )
    {
    Thread t = new Thread(userLoca tion);
    int g = p2[i].getGPSID();
    t.Start(g);
    }

    }

    public static void userLocation(ob ject gpsid)
    {

    // generate the position x and y
    ht.Add(gpsid, new Location(x, y));

    }

    i have read a tutorial about multithreading however am not sure if this is the right
    way so that all the new created thread will work concurrently

    thanks a lot;
  • veljkoz
    New Member
    • Feb 2008
    • 3

    #2
    If you're just starting with multithreading I suggest that you use the BackgroundWorke r - it's simple to understand and easily implemented. You have it in your toolbox/components.
    Implement the DoWork event for it. You can pass arguments you need for it to work like this:

    myBackgroundWor ker.RunWorkerAs ync(myArguments );
    ...

    private void myBackgroundWor ker_DoWork(obje ct sender, DoWorkEventArgs e)
    {
    //here you can cast e.Argument to the type of myArguments and work with it.
    }

    If you need to do something upon the completion implement the RunWorkerComple ted. This event is raised when the DoWork event handler returns. (more info: msdn help on RunWorkerComple ted

    Comment

    • RiskyHunter
      New Member
      • Mar 2007
      • 29

      #3
      veljkoz thanks 4 ur reply;

      however, i really wanna knew whats the different (in term of functionalities ) between
      the two ways, the way that i implement the thread and the backgroundWorke r
      which way is much better;

      thanks a lot;

      Comment

      Working...