New to threading in C#, can you make thread methods generic and what are the dangers?

Posted by ibarczewski on Stack Overflow See other posts from Stack Overflow or by ibarczewski
Published on 2010-06-18T13:34:53Z Indexed on 2010/06/18 13:43 UTC
Read the original article Hit count: 168

Filed under:
|

Hey all,

I'm just now starting to get into the idea of threading, and wanted to know if I could make this more abstract. Both foo and bar derive methods from a base class, so I'd like to pass in one or the other and be able to do work using a method that was derived. I'd also like to know how you properly name threads and the methods inside threads.

    if (ChkFoo.Checked)
            {
                Thread fooThread = new Thread(new ThreadStart(this.ThreadedFooMethod));
                fooThread.Start();
            }
    if (ChkBar.Checked)
            {
                Thread barThread = new Thread(new ThreadStart(this.ThreadedBarMethod));
                barThread.Start();
            }
    .
    .
    .
    public void ThreadedFooMethod()
    {
    Foo newFoo = new Foo();
    //Do work on newFoo
    }

    public void ThreadedBarMethod()
    {
    Bar newBar = new Bar();
    //Do similar work
    }

Thanks all!

© Stack Overflow or respective owner

Related posts about c#

Related posts about multithreading