Thread

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • julien

    Thread

    Hello,
    on the following line:
    Thread startThread = new Thread(new
    ThreadStart(plu gin.StartPlugin (session)));

    I got an error from the C# compiler:
    [csc] c:\XXX\foo.cs(4 07,53): error CS0149: Method name expected

    Column 53 is the T of ThreadStart.

    I don't understand what is wrong. I' following the example given in the
    MSDN doc, and from another book.

    Thank you
    Julien
  • Jon Skeet [C# MVP]

    #2
    Re: Thread

    julien <julien@sobrier .net> wrote:[color=blue]
    > on the following line:
    > Thread startThread = new Thread(new
    > ThreadStart(plu gin.StartPlugin (session)));
    >
    > I got an error from the C# compiler:
    > [csc] c:\XXX\foo.cs(4 07,53): error CS0149: Method name expected
    >
    > Column 53 is the T of ThreadStart.
    >
    > I don't understand what is wrong. I' following the example given in the
    > MSDN doc, and from another book.[/color]

    I suspect you're not *quite* following the example - you're calling a
    method, rather than providing a method *name*. Normally you'd do:

    Thread startThread = new Thread (new ThreadStart (plugin.StartPl ugin));

    Note that if your method takes a parameter, you can't use it as a
    ThreadStart anyway.

    See http://www.pobox.com/~skeet/csharp/t...rameters.shtml

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • Eyal Safran

      #3
      Re: Thread

      Hi,

      ThreadStart is a delegator of kind:

      public delegate void ThreadStart();

      Which means you have to provide its constructor a method with a return
      type of VOID and does not receive any parameter.

      and in addition, you have to provide only the method name, without the
      ().

      In your code:
      plugin.StartPlu gin­(session)

      you provide a parameter "session".

      Eyal.

      Comment

      • julien

        #4
        Re: Thread

        Jon Skeet [C# MVP] a écrit :[color=blue]
        > julien <julien@sobrier .net> wrote:
        > [color=green]
        >>on the following line:
        >>Thread startThread = new Thread(new
        >>ThreadStart(p lugin.StartPlug in(session)));
        >>
        >>I got an error from the C# compiler:
        >>[csc] c:\XXX\foo.cs(4 07,53): error CS0149: Method name expected[/color][/color]
        ...[color=blue]
        > I suspect you're not *quite* following the example - you're calling a
        > method, rather than providing a method *name*. Normally you'd do:
        >
        > Thread startThread = new Thread (new ThreadStart (plugin.StartPl ugin));
        >
        > Note that if your method takes a parameter, you can't use it as a
        > ThreadStart anyway.
        >
        > See http://www.pobox.com/~skeet/csharp/t...rameters.shtml
        > [/color]

        Thank you

        I finally decided to use a delegate that I call asynchronously. I think
        the result will be the same: a new thread will be created for this call.

        Julien

        Comment

        Working...