本文整理汇总了C#中System.Threading.Thread.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# Thread.GetHashCode方法的具体用法?C# Thread.GetHashCode怎么用?C# Thread.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Thread
的用法示例。
在下文中一共展示了Thread.GetHashCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TcpEchoServerThreadMethod
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);
}
}
}
示例2: printThreadInfo
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();
}
示例3: FileRenderThread
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);
}
示例4: Communicator
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);
}
}
示例5: EndLoop
internal static void EndLoop(Thread thread) {
#if DriverDebug
Console.WriteLine("EndLoop({0:X}): Called", thread.GetHashCode());
#endif
driver.EndLoop(thread);
}
示例6: StartLoop
internal static object StartLoop(Thread thread) {
#if DriverDebug
Console.WriteLine("StartLoop({0:X}): Called", thread.GetHashCode());
#endif
return driver.StartLoop(thread);
}
示例7: New
/// <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;
}
示例8: ListenForDataOnSocket
/// <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;
}
示例9: StartThreads
/// <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;
}
}
}
示例10: TestUniqingScope
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." );
}
}
示例11: Start
/// <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());
}
示例12: StartThreads
/// <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;
}
}
}
示例13: Connect
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 = "[email protected]";
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();
}
示例14: startChatListen
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;
}
示例15: StartLoop
internal static object StartLoop (Thread thread)
{
DriverDebug ("StartLoop ({0:X}): Called", thread.GetHashCode ());
return driver.StartLoop (thread);
}