Schedule still only firsttime when access

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

tanvan
Posts: 5
Joined: 05 Jul 2021, 10:42

Schedule still only firsttime when access

Postby tanvan » 16 Jul 2021, 13:55

HI

I've code run on this link

https://smartfoxserver.com/blog/how-to-schedule-timed-tasks-in-an-extension/

This code run successfull and I modify code

Code: Select all

public void run() {
            trace("running code");

// New code
  try {
                String sql = "SELECT Id, IdUser, IdCategory FROM tblRequestGame";
                IDBManager dbManager = getParentZone().getDBManager();
                ISFSArray res = dbManager.executeQuery(sql, new Object[]{});
}  catch (SQLException e) {
                trace("Error: "+ e.getMessage());
            }finally {

            }
}

When I add new code, schedule run first time. After that, code not run

This code access DB, run correct. Help me
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Schedule still only firsttime when access

Postby Lapo » 16 Jul 2021, 15:14

Hi,
can you show us how the task is scheduled?

in your run() method you are only catching a SQLException, so any other runtime exception would be able to escape and interrupt the Task. The try catch should look like this instead:

Code: Select all

public void run()
{
  try
  {
    // code here...
  }
 
  catch (SQLException e)
  {
    trace("Error: "+ e.getMessage());
  }

  catch (Exception ex)
  {
    trace("Unexpected exception: " + ex.getMessage());
  }       
}


Also, in your code, I am not sure what the empty finally block would be supposed to do. Might as well remove it, if it doesn't run any code.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
tanvan
Posts: 5
Joined: 05 Jul 2021, 10:42

Re: Schedule still only firsttime when access

Postby tanvan » 20 Jul 2021, 12:43

thanks

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 27 guests