-
QueueUserWorkItem
It appears I can also call QueueUserWorkItem without a WaitCallBack constructor in the parameter list ...
Code:
static void Main(string[] args)
{
ThreadPool.QueueUserWorkItem(ThreadMethod);
Console.ReadKey();
}
static void ThreadMethod(Object objInfo)
{
Console.WriteLine("This is the threaded method.");
}
MSDN however states this is only allowed in VB ... http://msdn.microsoft.com/en-us/libr....90).aspx#Y108
Can anyone tell me which is preferred in C# ?
-
Re: QueueUserWorkItem
C# can automatically infer the type of the required delegate so everything works automatically. What you've written is the preferred way.
-
Re: QueueUserWorkItem
@zvenny: As for the MSDN article, it says:
"Visual Basic users can omit the WaitCallback constructor, and simply use the AddressOf operator when passing the callback method to QueueUserWorkItem. Visual Basic automatically calls the correct delegate constructor."
Although after reading this one can infer exactly what you've concluded, this statement doesn't actually say anything about other languages; I think it's just a note directed specifically at VB.NET developers to inform them about an option they may not be aware of.
-
Re: QueueUserWorkItem
Until yesterday, I did not know about delegate inference in C# :blush:
The comment in the MSDN article indeed made me think this was a VB feature.
Thx all :thumb: