GetHashCode() public method

public GetHashCode ( ) : int
return int
		void TcpEchoServerThreadMethod(string[] args)
		{
			//Check for correct amount of arguments.
			int servPort = (args.Length >= 1) ? Int32.Parse(args[0]) : 7;

			//Create a TcpListener Socket to accept client connection requests
			TcpListener listener = new TcpListener(IPAddress.Any, servPort);
			//Log to --------------v
			ILogger logger = new ConsoleLogger();
			listener.Start();

			//Run forever; accepting and spawning threads to service each connection
			while (true)
			{
				try
				{
					Socket clntSock = listener.AcceptSocket();
					EchoProtocol protocol = new EchoProtocol(clntSock, logger);
					Thread thread = new Thread(new ThreadStart(protocol.handleClient));
					thread.Start();
					logger.writeEntry("Created and started Thread = " + thread.GetHashCode());
				}
				catch (System.IO.IOException e)
				{
					logger.writeEntry("Exception = " + e.Message);
				}
			}
		}
Beispiel #2
0
 private static String printThreadInfo( Thread thread )
 {
     StringBuilder info = new StringBuilder(150);
     int threadId = thread.ManagedThreadId;
     info.AppendLine("THREAD INFO (" + threadId + ")");
     info.AppendLine("[" + threadId + "] Name: " + thread.Name);
     info.AppendLine("[" + threadId + "] ManagedThreadId: " + thread.ManagedThreadId);
     info.AppendLine("[" + threadId + "] HashCode: " + thread.GetHashCode());
     info.AppendLine("[" + threadId + "] IsAlive: " + thread.IsAlive);
     info.AppendLine("[" + threadId + "] IsBackground: " + thread.IsBackground);
     info.AppendLine("[" + threadId + "] IsThreadPoolThread: " + thread.IsThreadPoolThread);
     info.AppendLine("[" + threadId + "] Priority: " + thread.Priority);
     info.AppendLine("[" + threadId + "] ThreadState: " + thread.ThreadState);
     return info.ToString();
 }
Beispiel #3
0
        public FileRenderThread(IObject3D scene, DeviceManager dm, FileRenderSettings initRenderSettings)
        {
            this.renderSettings = initRenderSettings;

            renderSurface = new HiddenRenderSurface(dm, scene, renderSettings.Width, renderSettings.Height);

            frameCount = renderSettings.StartFrame;

            thread = new Thread(new ThreadStart(this.Run));

            // setup temp directory in case the user chooses to save to a file format other than bitmap
            tempDirectory = Application.StartupPath + thread.GetHashCode().ToString();

            // if not a bitmap make the temp directory
            if(renderSettings.FileFormat != FileFormat.bmp)
                Directory.CreateDirectory(tempDirectory);
        }
Beispiel #4
0
        public Communicator()
        {
            addr = IPAddress.Parse("127.0.0.1");
            localEP = new IPEndPoint(addr, 8000);
            serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            serverSocket.Bind(localEP);
            serverSocket.Listen(10);

            while (true)
            {

                Socket clientSocket = serverSocket.Accept();
                Thread receivingThread = new Thread(new ParameterizedThreadStart(ReceiveMessage));
                Console.WriteLine("recv thread {0} created", receivingThread.GetHashCode());
                receivingThread.Start((object)clientSocket);

            }
        }
Beispiel #5
0
		internal static void EndLoop(Thread thread) {
			#if DriverDebug
				Console.WriteLine("EndLoop({0:X}): Called", thread.GetHashCode());
			#endif
			driver.EndLoop(thread);
		}
        /// <summary>
        /// Begin the async reading process
        /// </summary>
        /// <param name="args"></param>
        public bool ListenForDataOnSocket()
        {
            if (!OwningConnection.IsConnected)
            {
                SocketDebug(5);
                return false;
            }

            if (m_ReceiveThread == null)
            {
                lock (m_ThreadSync)
                {
                    m_ReceiveThread = new Thread(new ThreadStart(DoListen));
                }
                m_ReceiveThread.IsBackground = true;
                m_ReceiveThread.Name = "TCP Receive Thread #" + m_ReceiveThread.GetHashCode();
                m_ReceiveThread.Start();
            }

            return true;
        }
Beispiel #7
0
		[Test] // bug #325566
		public void GetHashCodeTest ()
		{
			C1Test test1 = new C1Test ();
			Thread tA = new Thread (new ThreadStart (test1.TestMethod));
			int hA1 = tA.GetHashCode ();
			Assert.IsTrue (hA1 > 0, "#A1");
			tA.Start ();
			int hA2 = tA.GetHashCode ();
			Assert.AreEqual (hA1, hA2, "#A2");
			tA.Join ();
			int hA3 = tA.GetHashCode ();
			Assert.AreEqual (hA1, hA3, "#A3");
			Assert.AreEqual (hA1, tA.ManagedThreadId, "#A4");

			test1 = new C1Test ();
			Thread tB = new Thread (new ThreadStart (test1.TestMethod));
			int hB1 = tB.GetHashCode ();
			Assert.IsTrue (hB1 > 0, "#B1");
			tB.Start ();
			int hB2 = tB.GetHashCode ();
			Assert.AreEqual (hB1, hB2, "#B2");
			tB.Join ();
			int hB3 = tB.GetHashCode ();
			Assert.AreEqual (hB1, hB3, "#B3");
			Assert.AreEqual (hB1, tB.ManagedThreadId, "#B4");
			Assert.IsFalse (hA2 == hB2, "#B5");
		}
Beispiel #8
0
    /// <summary>
    /// Starts a given number of threads. Increases the number of threads in the threadpool.
    /// Note: shutdown of idle threads is handled by the threads themselves in ProcessQueue().
    /// </summary>
    /// <param name="count">number of threads to start</param>
    private void StartThreads(int count)
    {
      // Don't start threads on shutdown
      if (!_run)
        return;

      lock (_syncObj)
      {
        for (int i = 0; i < count; i++)
        {
          // Make sure maximum thread count never exceeds
          if (_threads.Count >= _startInfo.MaximumThreads)
            return;

          Thread t = new Thread(ProcessQueue) {IsBackground = true};
          t.Name = "Thread" + t.GetHashCode();
          t.Priority = _startInfo.DefaultThreadPriority;
          t.Start();
          ServiceRegistration.Get<ILogger>().Debug("ThreadPool.StartThreads(): Thread {0} started", t.Name);

          // Add thread as key to the Hashtable with creation time as value
          _threads[t] = DateTime.Now;
        }
      }
    }
Beispiel #9
0
		internal static void EndLoop (Thread thread)
		{
			DriverDebug ("EndLoop ({0:X}): Called", thread.GetHashCode ());
			driver.EndLoop (thread);
		}
Beispiel #10
0
			public Object CMD (Int32 id, String argstr) {
				List<String> args = argstr.Split(' ').ToList();
				var t = new Thread(() => HandleWithCatch("CMD",id,args)); t.Start();
				Log.TRACE("Started New Thread ["+t.GetHashCode()+"] For EBO Request #"+id+": "+argstr);
				return t;
			}
Beispiel #11
0
		public void TestUniqingScope()
		{
			GentleSettings.CacheObjects = true;
			GentleSettings.SkipQueryExecution = false;
			GentleSettings.UniqingScope = UniqingScope.Thread;
			CacheManager.Clear();
			ObjectMap map = ObjectFactory.GetMap( Broker.SessionBroker, typeof(MailingList) );
			if( map.CacheStrategy != CacheStrategy.Never )
			{
				// access in this thread (populates cache)
				int cacheCount1stThread = CacheManager.Count;
				l1 = MailingList.Retrieve( 1 );
				Assert.IsTrue( CacheManager.Count == ++cacheCount1stThread, "Item was not added to cache." );
				l2 = MailingList.Retrieve( 1 );
				Assert.IsTrue( CacheManager.Count == cacheCount1stThread, "Item was added to cache again." );
				Assert.AreSame( l1, l2, "Object references are supposed to be identical." );
				Check.LogInfo( LogCategories.General, "TestUniqingScope --- after execution (thread {0}):", SystemSettings.ThreadIdentity );
				GentleStatistics.LogStatistics( LogCategories.Cache );
				// access same type in separate thread
				Thread thread = new Thread( RetrieveSpecificList );
				// remember the threads id (check for name to match SystemSettings.ThreadIdentity behavior)
				string threadId = thread.Name != null ? thread.Name : thread.GetHashCode().ToString();
				int cacheCount2ndThread = CacheManager.GetCount( threadId );
				thread.Start();
				thread.Join(); // wait for completion
				// we should see only a mailinglist being added to the cache
				Assert.AreEqual( cacheCount1stThread, CacheManager.Count, "Item was added to wrong cache store." );
				Assert.AreEqual( ++cacheCount2ndThread, CacheManager.GetCount( threadId ), "Item was not added to cache for 2nd thread." );
				Check.LogInfo( LogCategories.General, "TestUniqingScope --- after execution (thread {0}):", thread.GetHashCode() );
				GentleStatistics.LogStatistics( LogCategories.Cache );
				// under normal circumstances we should make sure to clean items belonging to the 
				// terminated thread; lets test that this works too :)
				CacheManager.Clear( threadId );
				Assert.AreEqual( --cacheCount2ndThread, CacheManager.GetCount( threadId ), "Items were not properly flushed from the cache." );
			}
		}
 /// <summary>
 /// Start the server thread.
 /// </summary>
 public void Start()
 {
     // start server
     this.serverThread = new Thread(RunServer);
     serverThread.Start();
     Debug.Print("Started server in thread " + serverThread.GetHashCode().ToString());
 }
Beispiel #13
0
    /// <summary>
    /// Starts a given number of threads. Increases the number of threads in the threadpool.
    /// Note: shutdown of idle threads is handled by the threads themselves in ProcessQueue().
    /// </summary>
    /// <param name="count">number of threads to start</param>
    private void StartThreads(int count)
    {
      // Don't start threads on shutdown
      if (!_run)
      {
        return;
      }

      lock (_threads.SyncRoot)
      {
        for (int i = 0; i < count; i++)
        {
          // Make sure maximum thread count never exceeds
          if (_threads.Count >= _startInfo.MaximumThreads)
          {
            return;
          }

          Thread t = new Thread(new ThreadStart(ProcessQueue));
          t.IsBackground = true;
          t.Name = "PoolThread" + t.GetHashCode();
          t.Priority = _startInfo.DefaultThreadPriority;
          t.Start();
          LogDebug("ThreadPool.StartThreads() : Thread {0} started", t.Name);

          // Add thread as key to the Hashtable with creation time as value
          _threads[t] = DateTime.Now;
        }
      }
    }
        public void Connect(string username, string password)
        {
            if (_TcpClient.Connected == false)
            {
                _TcpClient.Connect(HOST, PORT);

                Prompt prompt = new Prompt();
                prompt.status = Status.Connected;
                this.ShowPrompt(prompt);
            }
            if (_ServerStream == null)
            {
                _ServerStream = _TcpClient.GetStream();
            }

            UserAccount usr = new UserAccount();
            usr.username = string.IsNullOrEmpty(username) ? "Guest" : username;
            usr.email = "*****@*****.**";
            string jstr = JS.Serialize<UserAccount>(usr);

            this.SendRaw(jstr);

            Thread task = new Thread(() =>
            {
                _ServerStream = _TcpClient.GetStream();

                try
                {
                    byte[] bytes = new byte[BUFFER_SIZE];
                    int bytesRead = _ServerStream.Read(bytes, 0, bytes.Length);
                    UserAccount user = JS.Deserialize<UserAccount>(bytes, bytesRead);

                    if (this.IsLoggedIn(user))
                    {
                        this._User = user;

                        Prompt prompt = new Prompt();
                        prompt.status = Status.LoggedIn;
                        this.ShowPrompt(prompt);

                        startChatListen();
                    }
                }
                catch(Exception ex)
                {
                    Prompt prompt = new Prompt();
                    prompt.status = (int)Status.LoggingError;
                    prompt.description = ex.Message;
                    this.ShowPrompt(prompt);
                }
            });
            _Threads.Add(task.GetHashCode(), task);
            task.Start();
        }
        private Thread startChatListen()
        {
            Thread task = new Thread(() =>
            {
                while (true)
                {
                    if (!_TcpClient.Connected)
                    {
                        Prompt prompt = new Prompt();
                        prompt.status = (int)Status.Disconnected;
                        this.ShowPrompt(prompt);
                        break;
                    }

                    _ServerStream = _TcpClient.GetStream();

                    try
                    {
                        byte[] bytes = new byte[BUFFER_SIZE];
                        int bytesRead = _ServerStream.Read(bytes, 0, bytes.Length);
                        Message message = JS.Deserialize<Message>(bytes, bytesRead);

                        this.ShowMessage(message);
                    }
                    catch
                    {
                        Prompt prompt = new Prompt();
                        prompt.status = (int)Status.CannotReceived;
                        this.ShowPrompt(prompt);
                        break;
                    }

                    Thread.Sleep(500);
                }
            });
            _Threads.Add(task.GetHashCode(), task);
            task.Start();
            return task;
        }
Beispiel #16
0
 public override int GetHashCode()
 {
     return(_thread == null?ToString().GetHashCode() : _thread.GetHashCode());
 }
Beispiel #17
0
		internal static object StartLoop (Thread thread)
		{
			DriverDebug ("StartLoop ({0:X}): Called", thread.GetHashCode ());
			return driver.StartLoop (thread);
		}
Beispiel #18
0
 //   public abstract string Execute(string function, Dictionary<string, string> parameter);
 /// <summary>
 /// Startet die Abarbeitung der Modulfunktion.
 /// </summary>
 /// <param name="function">Name der Funktion - entspricht dem Schlüssel in dem Dictionary functionPointerDictionary.</param>
 /// <param name="parameter">Die Parameter die an die Funktion übergäben werden.</param>
 /// <returns></returns>
 public string Execute(string function, Dictionary<string, string> parameter)
 {
     // Neuen Thread erstellen
     Thread t = new Thread(new ThreadStart(Run));
     // Dem Thread einen Namen zuweisen um ihn später zu identifizieren
     t.Name = ""+t.GetHashCode();
     MessageBox.Show("Thread mit Namen gestertet: "+t.Name);//TEST
     // Funktionsparameter zwischenspeichern
     requestFunctionParameter = parameter;
     // Funktionszeiger zwischenspeichern
     requestFunction = GetModulFunction(function);
     t.Start();
     threadsInWork++;
     threadList.Add(t.Name, t);
     // Wen die Funktionen der Mudule paralell abgearbeitet werden könn, muss die Funktion in einem Thread gestertet werden
     // und ert wenn der Thread zu Ende ist, darf das Event weiter gegeben werden.
     return null;
 }
Beispiel #19
0
 public override int GetHashCode()
 {
     return(_Thread.GetHashCode());
 }
Beispiel #20
0
 /// <summary>
 /// Create a new <see cref="FJTaskRunner"/>, setting its thread
 /// as needed
 /// </summary>
 public static FJTaskRunner New(FJTaskRunnerGroup runnerGroup)
 {
     FJTaskRunner runner = new FJTaskRunner(runnerGroup);
     Thread t = new Thread(new ThreadStart(runner.DoStart));
     t.Name = "FJTaskRunner thread #" + t.GetHashCode();
     runner.SetThread(t);
     return runner;
 }
Beispiel #21
0
 public override int GetHashCode()
 {
     // review - [....]
     return(_thread == null?ToString().GetHashCode() : _thread.GetHashCode());
 }
Beispiel #22
0
 public override int GetHashCode()
 {
     return(_thread == null ? 37 : _thread.GetHashCode());
 }
 public override int GetHashCode()
 {
     return(_thread?.GetHashCode() ?? 0);
 }
Beispiel #24
0
		internal static object StartLoop(Thread thread) {
			#if DriverDebug
				Console.WriteLine("StartLoop({0:X}): Called", thread.GetHashCode());
			#endif
			return driver.StartLoop(thread);
		}
 public void InitTCP()
 {
     OwningConnection.MyTCPSocket.Blocking = true;
     lock (m_ThreadSync)
     {
         m_SendThread = new Thread(new ThreadStart(DoSend));
     }
     m_SendThread.IsBackground = true;
     m_SendThread.Name = "Network Send Thread #" + m_SendThread.GetHashCode();
     m_SendThread.Start();
 }
 /// <summary>
 /// Start the server thread.
 /// </summary>
 public void Start(Socket nonBlockingSocket)
 {
     // start server
     this.currentThread = new Thread(ThreadMain);
     _ConnectionSocket = nonBlockingSocket.Accept();// connect in WebServer thread not Web response thread
     currentThread.Start();
     Thread.Sleep(1); // context switch hopefully
     Debug.Print("Started server in thread " + currentThread.GetHashCode().ToString());
 }