This delegate takes ParameterizedThreadStart takes an object but can be called wirhout parameter

Hi!

The delegate ParameterizedThreadStart is declared as taking one parameter of 
type object and returning void like this
public delegate void ParameterizedThreadStart(Object obj)

So according to the delegate the method signature should be void 
ParameterizedThreadStart(Object obj)
In this example when I use the method ThreadWorkWithParam which is based on 
the delegete ParameterizedThreadStart and look like this
private static void ThreadWorkWithParam(object param)
{
.. . .
}
I call the method ThreadWorkWithParam without passing a argument I just call 
is like this
t1.Start();

It seems to me that the compiler is kindly enough to let me skip passing an 
argument ?
If I for example call this method like this
ThreadWorkWithParam();
I get of cource compile error.
I thought that you have to pass an argument when the delegate is specified 
as taking an argument.

class Program
    {
        static void Main(string[] args)
        {
            Thread t1 = new Thread(new 
ParameterizedThreadStart(ThreadWorkWithParam));
            t1.Name = "ParamThread";
            t1.Start();

            for (int j = 0; j < 10; j++)
            {
                Console.WriteLine("Main thread :" + j);
                Thread.Sleep(500);
            }
            t1.Join();
            Console.WriteLine("Press any...");
            Console.ReadKey();
        }

        private static void ThreadWorkWithParam(object param)
        {
            for (int i = 0; i < (int)param; i++)
            {
                Console.WriteLine(Thread.CurrentThread.Name + " :" + i);
                Thread.Sleep(1000);
            }
        }
    }

//Tony 


0
Tony
5/12/2010 3:02:43 PM
dotnet.languages.csharp 1931 articles. 0 followers. Follow

2 Replies
1215 Views

Similar Articles

[PageSpeed] 50

Tony Johansson wrote:
> Hi!
> 
> The delegate ParameterizedThreadStart is declared as taking one parameter of 
> type object and returning void like this
> public delegate void ParameterizedThreadStart(Object obj)
> 
> So according to the delegate the method signature should be void 
> ParameterizedThreadStart(Object obj)
> In this example when I use the method ThreadWorkWithParam which is based on 
> the delegete ParameterizedThreadStart and look like this
> private static void ThreadWorkWithParam(object param)
> {
> .. . .
> }
> I call the method ThreadWorkWithParam without passing a argument I just call 
> is like this
> t1.Start();
> 
> It seems to me that the compiler is kindly enough to let me skip passing an 
> argument ? [...]

The compiler doesn't have anything to do with it.  On the statement 
where you call the Start() method, the compiler has no way to know that 
you used the Thread(ParameterizedThreadStart) constructor overload to 
create the object, and so could not detect and report any error based on 
that information.  All it knows is that you've got a Thread object, and 
that you're calling the parameterless Start() method overload.

It is then up to the Thread object itself to deal with the fact that you 
constructed it with a delegate for the entry point that requires an 
argument, but are trying to start it without passing an argument.  As 
the documentation says:

     Note:

     If this overload is used with a thread created using
     a ParameterizedThreadStart delegate, null is passed
     to the method executed by the thread.

Hope that helps.

Pete
0
Peter
5/12/2010 3:27:25 PM
"Tony Johansson" <johansson.andersson@telia.com> wrote in message 
news:O19%23qQe8KHA.3540@TK2MSFTNGP06.phx.gbl...
> The delegate ParameterizedThreadStart is declared as taking one parameter 
> of type object and returning void like this
> public delegate void ParameterizedThreadStart(Object obj)
> [...]
> I call the method ThreadWorkWithParam without passing a argument I just 
> call is like this
> t1.Start();
>
> It seems to me that the compiler is kindly enough to let me skip passing 
> an argument ?

    Yes this is documented.
    The Start method has two overloads, with and without a parameter. Under 
normal circumstances, you would use the overload without parameter when the 
delegate is a ThreadStart, and the overload with a parameter if the delegate 
is a ParameterizedThreadStart.
    So, what happens if you mix them?
    In the first case, when you use Start() with a ParameterizedThreadStart 
(which is what you mentioned in your question), the manual says: "If this 
overload is used with a thread created using a ParameterizedThreadStart 
delegate, null is passed to the method executed by the thread."
    In the opposite case, i.e., if you call Start(something) when the 
delegate is a ThreadStart, the manual says: "[Exceptions] [...] 
InvalidOperationException - This thread was created using a ThreadStart 
delegate instead of a ParameterizedThreadStart delegate."


0
Alberto
5/12/2010 3:35:39 PM
Reply:

Similar Artilces:

Can callout developed by .net 1.1 call web service developed by ne
Hi I am developing MS CRM and i need to integrate with other system which implemented by VS 2005 .NET 2.0. The part of integration is when user insert or update company in CRM, then it must be auto update company in other system also. The updating should be synchronizing. What i am thinking is i customized at Post Create, Post Update, Post delete of company entity of CRM, then in the code i will go to call web service which coded by .net 2.0 to proceed modify, or inseret company record in other system. My problem is from what i understand that CallOut has to code and compile by .....

Expression Calling Public Function In Access 2007
Hello Everyone, I have a perfectly functioning db in 2000-02 and 03. On a calendar form, that lives inside another form, I have all the day buttons OnClick event tied to an expression that points to a public function in the forms code container. Looks like this =ClickMe(11). Code Looks like this: Public Sub ClickMe(ByVal iLabelNum As Integer) DoCmd.Hourglass True Me.Repaint Call SelectDay(("lbl" & CStr(iLabelNum))) DoCmd.Hourglass False Exit Sub In Access 2007 (either in 2002 or converted to 2007), I receive an error: something about "The expression On Click you e...

Can I import old email from Eudora to MS Outlook 2007?
I've been using Eudora for years, and have limped along since they stopped providing updates. It's time to change and I have a lot of old emails I wish to preserve. Can I import that into Outlook 2007? ...

Can MSCRM_CONFIG be renamed (in SQL)?
Question is from one of our customers. I believe not... Just say no. kinda like those t-shirts in the 80s. Dave Ireland "Alex (crm-resultants.nl)" <Alexcrmresultantsnl@discussions.microsoft.com> wrote in message news:BE7200E8-A6FD-468E-ACC1-F33F48A7806D@microsoft.com... > Question is from one of our customers. > I believe not... ...

Unable to get DxgkDdiRecommendFunctionalVidPn call in windows 7
I am trying to add an initial vidpn topology by implementing the DxgkDdiRecommendFunctionalVidPn call in the WDDM miniport driver. But starting from windows 7 i am unable to get the DxgkDdiRecommendFunctionalVidPn function call from dxgkrnl.After searching through the MSDN documentation i found out that the function is deprecated starting from windows 7. msdn link: http://msdn.microsoft.com/en-us/library/ee220395.aspx According to msdn "On a computer running Windows 7, the display mode manager (DMM) determines an appropriate VidPN topology to apply using VidPN history d...

HELP!!! Can't get forumla figured out!
Hello, This is my first posting to this forum, and I haven't been able to search using the right criteria (not even sure what I would search under) to find what I need so I thought I would post a thread with the question. I have an access query that gives me the results in a spreadsheet layout, with 2 worksheets on it. I need to create a forumla that will look at the data on the 2nd sheet and compare the values in 2 particular columns with the value in one cell on the 1st sheet and populate a different cell on the 1st sheet with a count of entries from the 2nd sheet. If Sheet B, Colu...

I can not set an msn account
Hi. I could set a free hotmail account using outlook. I receintly bought an extra storage account using msn. Now I have problems trying to set the msn account using outlook, in spite I could set the hotmail account without problem. I can read and send mail using the browser. Can somebody help me to set the msn account using outlook? I am receiving the error message: Configuration: Account: MSN Server: http://services.msn.com/svcs/hotmail/httpmail.asp User name: username@msn.com Protocol: HTTPMail Port: 0 Secure(SSL): 0 Code: 800ccc19 ...

Can't access hotmail using Outlook Connector for MSN
I can't seem to download anything from my hotmail account into Outlook after setting up a link with Outlook Connector for MSN. Anyone have any ideas? ...

can't delete dupicate appointments, message object is not valid
I just instaled Office XP, on to Windows 7. I then updated all of my contact details from my Windows PDA to outlook. I now have duplicate entries for birthdays, aniversaries etc........... The contacts that the birthdays, aniversaries belong to, have not been created as contacts, when i try to recreate the contact details my system tells me that they are all ready there but are not shown. & when try to detect & repair the instal the same thing happens again. Outlook 2002 and Windows 7? That is not supported and buggy - its hard to say how much of the problems are beca...

Can't get my Focus
I have a form(frmProducts) on a tab control object (TabClt) that is on another form(frmOrders). I have a search box on frmProducts that filters "On change" and then keeps its focus in that box. Private Sub txtDescSearch_Change() DoCmd.ShowAllRecords Me.Filter = "Description like '" & txtDescSearch & "*'" Me.FilterOn = True Me.txtDescSearch.SetFocus SendKeys "{F2}" End Sub It works fine when I open frmProducts by itself but when I open the tab it is on from frmOrders. When I enter the first search letter it does fi...

Intelligent Message Filter- can the junk email feature be turned o
I am wondering if there is a reg hack or other method of running the Intelligent Message Filter but disabling the feature to send stuff to junk email? I have temporarily uninstalled it for customer since there were too many complaints about stuff going into to junk email. The filter capacity for the most part works pretty well and what is going into archieve looks like SPAM with only minor exceptions. I was looking at reinstalling the Intelligent Message Filter and not setting the second setting –Store Junk Email Configuration. Although I intially had the settings SCL lower I raised...

HELP SCREENS, can't get help..
HELP SCREENS, can't get help.. 100723 1900 no pun.. can't get help on how to turn off "TILE" windows if using the term correctly. had seen setting somewhere, to stop Excel from minimizing to a narrow window when help opens (how the heck supposed to compare help to work doing when reducing window on us: cannot read window). where is the setting to stop windows / excel help from resizing to a narrow screen, when you open help. Top left of the help window autotile icon (looks like double page). It toggles between the help andexcel windows being tiled and vo...

The database is in an unexpected state; Microsoft Access can't open it.
This morning I encountered an unusual and scary problem. While trying to open one of our databases I recieved this error. The database is in an unexpected state; Microsoft Access can't open it. This database has been converted from a prior version of Microsoft Access by using the DAO CompactDatabase method instead of the Convert Database command on the Tools menu (Database Utilities submenu). This has left the database in a partially converted state. If you have a copy of the database in its original format, use the Convert Database command on the Tools menu (Database Utilities submenu) ...

RE: msimn.exe R6025 Pure Virtual Function Call
I had the same problem and this worked for me when nothing else listed here did.. Uncheck the block attachments box in options, hit apply and exit restart.. on another machine, same problem had to copy a few messages to the folder which was causing the problem when opened first... Both times it was related to a clean forwarded email from a yahoo.com mailbox. Something in the html or other code caused the error.. If this is still an issue to you send me an email and I will see what else I can do to help.. version of OS and outlook express would be help full.. Qube > "Abbie" <a...

can't access all of my back up after using Osirius program
Hi, I have Windows XP with Outlook 2003. I have backed up my massive amount of emails (400MB) using Outlook Backup from Osirius. Having used this program for smaller amounts of emails with no problems before I then placed the backup onto a disc and formatted the drive. After loading XP and Outlook back on I then tried to restore my backup using the same program. But it runs through the restore procedure without any problems and when I open Outlook up again most of the emails are not there. Outlook Backup has restored my deleted items and my sent items and also all of my accounts as th...

why can't I edit a document I created two days ago with same Word
Started using Windows 7 about two weeks ago. Now I can't edit files I just created within the last week using the Word 2007. Why? Hi, I am really sorry that you are experiencing that. I am not quite sure yet thatI fully understand your problem but from what I see it seems taht you are trying to modify a read only file. Make sure taht when you save in word you are not saving the document as "read only." Let me know if this helps and if you have any additional info I would be glad to help you . -- Vicente Tulliano "veteranpoet" wrote: > ...

Can't use Hebrew in Microsoft fonts, yet they show in taskbar.
I've downloaded Hebrew fonts. And they even appear in the taskbar. Yet all characters in these fonts still are Roman. How do I switch on the Hebrew font?? You need to activate Hebrew in Windows. Go to Start > Control Panel > Regional and Language Options, and then follow the tabs and buttons to add a "Keyboard" (not to add a "Language"). The three Windowses do this a bit differently. If you're in XP, at one point you have to check off "Complex Scripts." Once you've done that, you'll have a new icon toward the right end of you...

can't telnet from a computer
I have an Exchange 2003 box. I have a problem telneting to the exchange server from a particular computer. All computer on the network can attach except for one. Any ideas? Thanks Telnet as in standard telnet app (port 23) or telnet to a particular service port like smtp (25)? Do you mean all computers in the network can telnet to Exchange except one? Can that computer telnet to any other server on the same port? -- Bharat Suneja MCSE, MCT -------------------------------- "Peretz Stern" <peretzstern@optonline.net> wrote in message news:%23BB%23o$brFHA.2272@TK2M...

Outlook 2002-can't reply. Get "undeliverable" from System Administrator
When I reply, I am getting the mail bounced back with the message: "Undeliverable: Subject of email" from the System Administrator. This is happening to most but not all emails. When I called my ISP, they said it was an Outlook glitch and that I should uninstall and then reinstall Outlook. Any other suggestions? If not, if I uninstall Outlook, will all my data be saved? Thanks, Wendy What is the complete error message? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. Due to the SWEN virus, all mail sent to my personal account ...

Operation failed. An object could not be found
I am presently using outlook express only because my outlook stopped working. Express works fine, but in Outlook, everytime I try to send any type of email I get the error message: "The operation failed. An object could not be found." It is Outlook 2002, w/SP-2 installed I've tried reinstalling the program but with no effect. Any ideas? Can you give more information on the actual error? What object? -- Nikki Peterson [MVP - Outlook] "Bill Thaden" <wathaden@writeme.com> wrote in message news:8f6001c34599$0f976a00$a401280a@phx.gbl... I am presently using o...

can it be done without notice?
Hi, The below code (which was given in this NG + With some minor alterations by me) intends to check if anything is changed on column J then email that changed info to a spesific email address without the notice of the workbook user... But it has two problems: 1. If Outlook Express is not opened beforehand, starting of OE is visible and the user recognizes that something without his/her control is going on. 2. If Outlook Express is active before the execution of the macro, yet again a small instance of mail being produced is visible on the screen. Can anyone suggest solutions for the 2 proble...

Can get UserProperty Names but not Values?
>From C++ using UserProp->Name I can get the name of a UserProperty, but UserProp->Value.bstrVal always returns nothing, anyone have any ideas what I could be doing wrong and has anyone ever accessed UserProperties from C++? UserPropertiesPtr UserProps = Con->UserProperties; if (UserProps->Count > 0) { tot = UserProps->Count; UserPropertyPtr UserProp; for (i=1;i < tot + 1;i++) { UserProp = UserProps->Item(i); MessageBox(NULL,UserProp->Name,"Test - Name",MB_OK); char* sText; sText = (char*)UserProp->Val...

Outlook2003: "the object cannot be found"
Hi I'm having trouble with a particular Outlook 2003 installation. On many actions in Outlook the message "the object cannot be found" is displayed and the action fails. For example: -Forwarding a Contact -Clicking on mailto: link in an e-mail How can I solve or debug this problem? TIA Dieter ...

re-enabled user, now can't access mail container
i have a user who's account was disabled, i enabled the user and i changed the users password. i then logged in as that user and setup her outlook xp for her exchange account thinking i could then access the user's mail. however i get an error message: Unable to open your default e-mail folders. The attempt to log onto the Microsoft Exchange Server computer has failed. (Exchange) Any Ideas? I have to forward messages to my boss. TIA, Mike Hello Mike, Go to control panel and click on mail, that is where you will verify user account for exchange. Lowell "Mike Smith...

How can I save an email in Outlook to offline storage?
I am new to Outlook. Previously, I saved my emails, after reading, to a zip disk, in a WORD document, and organized them according to subject. I cannot find a way in Outlook 2003 to do this. There is no "save" or "save as" in the Files list; it is greyed out. How can I continue to save my emails as I desire? If you open a mail item you can use the File menu > Save option there to save an item individually or you can copy/export them to another PST file for storage together with other mail items/folders "Sandyc" <Sandyc@discussions.microsoft.com...