嗨我有以下代码,当我第一次调用 Ping 方法时,它可以工作,但是在第二次调用时它失败并出现错误 Ping 服务意味着保持活动 16 秒,一旦计时器计数为零用户从数据表中删除,这样我就有了当前连接用户的列表
public class PokerHost : WebService
{
//bool RunningTimmer = true;
static DataTable table = new DataTable();
private static readonly TimeSpan UpdateEngineTimerFrequency = TimeSpan.FromSeconds(2);
private Timer UpdateEngineTimer { get; set; }
private void MyTimerAction(object state)
{
DataTable table = GetTable(); // Get the data table.
foreach (DataRow row in table.Rows) // Loop over the rows.
{
int minused = Convert.ToInt32(row["countdown"]) - 2;
if (minused >= 0) {
row["countdown"] = minused;
}
else
{
row.Delete();
}
table.AcceptChanges();
}
}
static DataTable GetTable()
{
table.Columns.Add("gamekey", typeof(string));
table.Columns.Add("countdown", typeof(int));
return table;
}
protected void Application_Start(object sender, EventArgs e)
{
this.UpdateEngineTimer = new Timer(MyTimerAction,
null, /* or whatever state object you need to pass */
UpdateEngineTimerFrequency,
UpdateEngineTimerFrequency);
}
protected void Application_End(object sender, EventArgs e)
{
this.UpdateEngineTimer.Dispose();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------
//--Only webmethods
//--------------------------------------------------------------------------------------------------------------------------------------------------
[WebMethod]
public string Ping(string gamekey)
{
DataTable table = GetTable(); // Get the data table.
foreach (DataRow row in table.Rows) // Loop over the rows.
{
if (Convert.ToString(row["gamekey"]) == gamekey)
{
row["countdown"] = 16;
}
table.AcceptChanges();
table.Dispose();
}
//make array of current online users
// need to check with the game and timelimits
table.AcceptChanges();
table.Dispose();
return "PONG";
}
一旦第二次调用该方法被杀死,我该如何解决这个问题,
感谢您的时间,这个应用程序是在 ubuntu 服务器上以单声道制作和运行的
我得到的错误是这个
500 - Internal Server Error
System.Data.DuplicateNameException: A DataColumn named 'gamekey' already belongs to this DataTable.
at System.Data.DataColumnCollection.RegisterName (System.String name, System.Data.DataColumn column) [0x00000] in <filename unknown>:0
at System.Data.DataColumnCollection.Add (System.Data.DataColumn column) [0x00000] in <filename unknown>:0