?? talker.cs
字號:
namespace RemotingChat
{
using System;
using System.Threading;
using System.Collections;
/// <summary>
/// Summary description for Talker.
/// </summary>
public class Talker
{
private ObjectList messages = new ObjectList();
private Chat c;
bool isActive = true;
private String name;
private Thread t=null;
public Talker(Chat c,String name) {
this.c = c;
this.name=name;
t=new Thread(new ThreadStart(this.run));
t.Start();
}
public bool addMessage(Message e){
if(!isActive)
return false;
messages.Add(e);
if(t.ThreadState==ThreadState.Suspended)
{
t.Resume();
}
return true;
}
public void run()
{
while(true)
{
try
{
if(messages.Count==0)
t.Suspend();
c.chatNotify((Message)messages[0]);
messages.RemoveAt(0);
}
catch (ArgumentOutOfRangeException e)
{
Console.WriteLine("postMessage: " + e);
}
catch (Exception e)
{
//Some Error when more than one Client is connected.
Console.WriteLine("Removing "+ name + "\n" + e);
isActive=false;
t.Abort();
}
}
}
public String getChatterName() {
return name;
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -