Results 1 to 3 of 3

Thread: Thread Error -Pls help

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    Thread Error -Pls help

    Hello Everybody

    I am trying to define a thread process as a bool .But getting erro as Method name expected... Pls guide what is the problem???

    private bool abClientProcess;


    tcpThd=new Thread(new ThreadStart(ClientProcess( abClientProcess)));

    public void ClientProcess( bool abClientProcess)

    {

    // Code Write to connect to the server.....

    }


    Pls guide..

    Thanks,

    Rahil

  2. #2
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    The constrctor for a Thread class accepts a ThreadStart delegate. Whatever method you pass to Thread constructor must match the ThreadStart delegate. The ThreadStart delegate has no parameters, and your ClientProcess method does; you need to remove the param from that method. If you need to pass values into your ThreadStart delegate you can do something like this:
    PHP Code:
    using System;
    using System.Threading;

    namespace 
    Tester
    {
        public class 
    MainApp
        
    {
            public static 
    void Mainstring[] args )
            {
                
    Worker worker = new Worker("Chris");
                
    Console.WriteLine("Before: Worker valid? {0}"worker.Valid);
                
    Thread t = new Thread(new ThreadStart(worker.DoSomething));
                
    t.Start();
                while(
    t.IsAlive && !worker.Valid)
                {
                    
    Thread.Sleep(200);
                }
                
    Console.WriteLine("After: Worker valid? {0}"worker.Valid);
                
    Console.WriteLine("Done...");
                
    Console.ReadLine();
            }
        }
        public class 
    Worker
        
    {
            private 
    string _name "";
            private 
    bool _valid false;
            public 
    bool Valid
            
    {
                
    get
                
    {
                    return 
    _valid;
                }
                
    set
                
    {
                    
    _valid value;
                }
            }
            public 
    string Name
            
    {
                
    get
                
    {
                    return 
    _name;
                }
                
    set
                
    {
                    
    _name value;
                }
            }
            public 
    Worker(string name)
            {
                
    this._name name;
            }
            public 
    void DoSomething()
            {
                
    this._valid true;
                
    Console.WriteLine("Hello {0} from the ThreadStart delegate"this.Name);
            }
        }


  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    THanks

    Thanks for the information..

    Rahil


    Originally posted by pvb
    The constrctor for a Thread class accepts a ThreadStart delegate. Whatever method you pass to Thread constructor must match the ThreadStart delegate. The ThreadStart delegate has no parameters, and your ClientProcess method does; you need to remove the param from that method. If you need to pass values into your ThreadStart delegate you can do something like this:
    PHP Code:
    using System;
    using System.Threading;

    namespace 
    Tester
    {
        public class 
    MainApp
        
    {
            public static 
    void Mainstring[] args )
            {
                
    Worker worker = new Worker("Chris");
                
    Console.WriteLine("Before: Worker valid? {0}"worker.Valid);
                
    Thread t = new Thread(new ThreadStart(worker.DoSomething));
                
    t.Start();
                while(
    t.IsAlive && !worker.Valid)
                {
                    
    Thread.Sleep(200);
                }
                
    Console.WriteLine("After: Worker valid? {0}"worker.Valid);
                
    Console.WriteLine("Done...");
                
    Console.ReadLine();
            }
        }
        public class 
    Worker
        
    {
            private 
    string _name "";
            private 
    bool _valid false;
            public 
    bool Valid
            
    {
                
    get
                
    {
                    return 
    _valid;
                }
                
    set
                
    {
                    
    _valid value;
                }
            }
            public 
    string Name
            
    {
                
    get
                
    {
                    return 
    _name;
                }
                
    set
                
    {
                    
    _name value;
                }
            }
            public 
    Worker(string name)
            {
                
    this._name name;
            }
            public 
    void DoSomething()
            {
                
    this._valid true;
                
    Console.WriteLine("Hello {0} from the ThreadStart delegate"this.Name);
            }
        }


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width