using delegate via a thread ???

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cmrchs@yahoo.com

    using delegate via a thread ???

    Hi,

    how can I call a method, being referenced by a delegate object, via a thread ?

    Here's what I try :

    public delegate void PrintDelegate() ;
    static void Print()
    {
    Console.WriteLi ne("Print()");
    }

    Main()
    {
    PrintDelegate pDel = new PrintDelegate(P rint);

    // call the function using a thread
    ThreadStart thStart = new ThreadStart(??? ); BUT HOW ???
    Thread th = new Thread(thStart) ;
    th.Start();
    }

    thnx
    Chris

    *************** *************** *************** *************** **********
    Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
    Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
  • Richard Blewett [DevelopMentor]

    #2
    Re; using delegate via a thread ???

    Does

    pDel.BeginInvok e

    work for you? Delegates have asynchronous behaviour built in.

    I wrote an article about their usage here

    Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology


    Regards

    Richard Blewett - DevelopMentor



    Hi,

    how can I call a method, being referenced by a delegate object, via a thread ?

    Here's what I try :

    public delegate void PrintDelegate() ;
    static void Print()
    {
    Console.WriteLi ne("Print()");
    }

    Main()
    {
    PrintDelegate pDel = new PrintDelegate(P rint);

    // call the function using a thread
    ThreadStart thStart = new ThreadStart(??? ); BUT HOW ???
    Thread th = new Thread(thStart) ;
    th.Start();
    }

    thnx
    Chris


    Comment

    • JoeWood

      #3
      RE: using delegate via a thread ???

      The ThreadStart object itself is a delegate, in the same way PrintDelegate is
      a delegate type.
      If you just have a void function() then use the ThreadStart delegate type
      instead of your PrintDelegate.
      If you're stuck with two different types of delegates and you want to use
      one type of delegate where another type is required then you can simply use
      the InvocationList of the delegate to create a ThreadStart object.

      "Chris C" wrote:
      [color=blue]
      > Hi,
      >
      > how can I call a method, being referenced by a delegate object, via a thread ?
      >
      > Here's what I try :
      >
      > public delegate void PrintDelegate() ;
      > static void Print()
      > {
      > Console.WriteLi ne("Print()");
      > }
      >
      > Main()
      > {
      > PrintDelegate pDel = new PrintDelegate(P rint);
      >
      > // call the function using a thread
      > ThreadStart thStart = new ThreadStart(??? ); BUT HOW ???
      > Thread th = new Thread(thStart) ;
      > th.Start();
      > }
      >
      > thnx
      > Chris
      >
      > *************** *************** *************** *************** **********
      > Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
      > Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
      >[/color]

      Comment

      Working...