using delegate via a thread ???

  • Thread starter Thread starter cmrchs
  • Start date Start date
C

cmrchs

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.WriteLine("Print()");
}

Main()
{
PrintDelegate pDel = new PrintDelegate(Print);

// 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...
 
Does

pDel.BeginInvoke

work for you? Delegates have asynchronous behaviour built in.

I wrote an article about their usage here

http://www.ondotnet.com/pub/a/dotnet/2003/02/24/asyncdelegates.html

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

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.WriteLine("Print()");
}

Main()
{
PrintDelegate pDel = new PrintDelegate(Print);

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

thnx
Chris
 
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.
 
Back
Top