Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8492865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:50:52+00:00 2026-06-10T22:50:52+00:00

HI I have the following code, when I call the Ping method the first

  • 0

HI I have the following code, when I call the Ping method the first time, it works but on the second call it fails with already exists error
the Ping service is meant to keep alive for 16 seconds, once the timer counts to zero the user is dropped from the datatable, this way I have a list of currently connected users

        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";
    }

As soon as the method is called the second time its killed , how do i fix this ,

Thanks for the time, this app is made and run in mono, on an ubuntu server

the error i am getting is this

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 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T22:50:54+00:00Added an answer on June 10, 2026 at 10:50 pm

    Your problem seems to be caused by attempting to set the same values to the variable table several times. You may be able to fix it by doing something like this:

    static DataTable table = null;
    
    static DataTable GetTable()
    {
        if(table == null){
            table = new DataTable();
            table.Columns.Add("gamekey", typeof(string));
            table.Columns.Add("countdown", typeof(int));
        }
        return table;
    }
    

    This is not an exact solution, and not tested in any way, but should hopefully give you an idea about what to try. The point is to only create and set values to table if it has not been done already (a simple singleton pattern).

    PS: If you want to / need to, you could also check if the table contains "gamekey" and "countdown", instead of just checking if it is null, as in the example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to call count_visit.php on onbeforeunload event. That works great.
I have the following code which gets call in my main activity's onCreate method
I have the following c# code to call stored procedure testproc , but when
I have the following code : This call the second form private void updateToolStripMenuItem_Click(object
I have the following code to make a jsonp call. var contacts; $.ajax({ url:
I have come up with the following code to call a webservice using client/server
I have the following code in html, I cannot get the Function call back
On Blackberry 6.0, I have used the following code to delete all the call
I have a problem with the following code, when executing the call to cublasSrotg
I have the following shortened classic ASP code that makes a SQL insert call...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.