using delegate via a thread ???

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...
 
R

Richard Blewett [DevelopMentor]

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top