|
-
February 19th, 2011, 10:11 AM
#1
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# ?
-
February 19th, 2011, 10:42 AM
#2
Re: QueueUserWorkItem
C# can automatically infer the type of the required delegate so everything works automatically. What you've written is the preferred way.
www.monotorrent.com For all your .NET bittorrent needs
NOTE: My code snippets are just snippets. They demonstrate an idea which can be adapted by you to solve your problem. They are not 100% complete and fully functional solutions equipped with error handling.
-
February 20th, 2011, 10:22 AM
#3
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.
-
February 20th, 2011, 02:10 PM
#4
Re: QueueUserWorkItem
Until yesterday, I did not know about delegate inference in C# 
The comment in the MSDN article indeed made me think this was a VB feature.
Thx all
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|