title: c++ this parameter through System::Threading:ThreadStart to class member function
body: <p>I'm writing in c++ a graphic user interfaced program and I need to create a threads in the program.
  so I'm using <code>System::Threading</code> namespace to get my goal.</p>
  
  <p>The function that I want to use as thread is a class member function, so here is what I've done:</p>
  
  <pre><code>Server::Server() // constructor
  {
      System::Threading::Thread^ T = gcnew System::Threading::Thread(gcnew System::Threading::ThreadStart(this, this-&gt;RunServer)); // Server::RunServer
      T-&gt;Start();
  }
  </code></pre>
  
  <p>since it gave me those errors:</p>
  
  <blockquote>
    <p>Error 2   error C3350: 'System::Threading::ThreadStart' : a delegate
    constructor expects 2 argument(s)</p>
    
    <p>Error 1   error C3867: 'Server::RunServer': function call missing
    argument list; use '&amp;Server::RunServer' to create a pointer to
    member</p>
  </blockquote>
  
  <p>I tried this call:</p>
  
  <pre><code>Server::Server() // constructor
  {
      System::Threading::Thread^ T = gcnew System::Threading::Thread(gcnew System::Threading::ThreadStart(&amp;Server::RunServer));
      T-&gt;Start();
  }
  </code></pre>
  
  <p>and received this errors:</p>
  
  <blockquote>
    <p>Error 1   error C3364: 'System::Threading::ThreadStart' : invalid
    argument for delegate constructor; delegate target needs to be a
    pointer to a member
    function</p>
    
    <p>2   IntelliSense: invalid delegate initializer -- function is not a
    member of a managed
    class</p>
  </blockquote>
  
  <p>as far as I know the second try did not succeed because <code>Server::RunServer</code> doesn't have address, so it's like to do <code>&amp;1</code>.</p>
  
  <p>by the way I tried to use the <code>ThreadStart</code> to create thread of none class memeber function and it worked fine.</p>
  
  <p>I'm using win7 - visual studio 2012. How to make it work?</p>
  
  <p>EDIT:
  Server declaration:</p>
  
  <pre><code>class Server
  {
  public:
  
      /* Fields */
      std::string Port;
      std::string Host;
      WSADATA wsaData;
      int ListenResult;
      SOCKET ListenSocket;
      SOCKET* ClientSocket;
      SOCKADDR_IN* ADDR;
      int ADDRSize;
      struct addrinfo *result;
      struct addrinfo hints;
      std::vector&lt;Client&gt; Clients;
  
      /* Methods */
      Server();
      std::wstring StringW(char* String);
      void Print(std::wstring String);
      std::wstring CurrentTime();
      void ParseServerIni();
      void RunServer();
      void PartToString(Part* _Part);
      void InsertListItem(std::string String);
      void ClientHandler(SOCKET* _Sock, SOCKADDR_IN* _ADDR);
      int ParsePacket(Packet &amp;_Packet, int _Bytes, Byte** _PacketBlock);
  
  };
  </code></pre>