+ Reply to Thread
Results 1 to 7 of 7

Thread: Unable to add event listeners - Multiple (UI) pages

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Unhappy Unable to add event listeners - Multiple (UI) pages

    I had developed a windows application using C# (.Net). I have two forms for login and game dashboard. I have defined the ElectroServer Instance in my common class file which i am using in both the pages. Following is the flow of the application, as soon as the user logs in following is the sequence of the API calls:

    1. Instantiate ES Instance. add listeners, call connect method.
    2. On successful ConnectionResponse send LoginRequest
    3. On successful LoginResponse redirect to next form (UI)

    On game dashboard (UI) page i try to use the same ES instance that is globally defined in the common class file as used in the login (UI) page. On this second (UI) page when i check for the ES instance connected flag, it shows true. But, i am not able to add new event listeners to the same ES instance for handling events requested in the game dasboard (UI) page.

    In brief the issue is how to add event listeners for multiple (UI) pages with plugin request being managed on these pages separately.

    Can somebody please help me out urgently with this?

  2. #2
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,219
    Thanks
    80
    Thanked 1,087 Times in 1,076 Posts
    You are creating an instance of ElectroServer in one class, and then other classes are getting it (using a public getter I assume, or having it injected).

    I'm not a .NET expert, and the generic C# examples that I made all had a single controller. I assume that if your local variable for the ElectroServer instance is "es" that you are using calls such as "es.Engine.JoinRoomEvent += OnJoinRoom;" in the other class. Note that you will need to remove the event listeners from other classes when you aren't using those, or you will end up with multiple classes firing each time a plugin event comes in.

    Can you give me a code snippet for how you are passing the ElectroServer instance around between the classes, and how you are trying to add the event listeners?
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  3. #3
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,219
    Thanks
    80
    Thanked 1,087 Times in 1,076 Posts
    Check your "using" lines too. Do you have both of these?
    using Electrotank.Electroserver5.Api;
    using Electrotank.Electroserver5.Core;
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi tcarr,

    Thanks so much for the quick reply. Following are my comments for your suggestions:

    Suggestion 1: Yes i am trying to add fresh event listeners in the new page. But once they are added they wont listen to any response from the server. I use the ElectroServer Instance defined in the common class file in both the UI pages.
    Suggestion 2: Yes I have both these using statements.

    Also, regarding suggestion 1, following is the code,

    Common Class File:

    namespace Game
    {
    class Common
    {
    #region "Variables"

    /* ElectroServer Instance */
    public static ElectroServer es;

    Login Page UI (Login.cs):

    Method to open connection & add listeners :

    public void ConnectToES()
    {
    Log("ConnectAndLogin constructor invoked");
    //Create new ElectroServer instance
    Common.es = new ElectroServer();
    Log("new ElectroServer made");
    Common.es.Engine.Queueing = EsEngine.QueueDispatchType.Internal;
    Log("EsEngine.QueueDispatchType.Internal");

    //listen for two events: ConnectionResponse and Login
    Common.es.Engine.ConnectionResponse += OnConnect;
    Common.es.Engine.LoginResponse += OnLogin;
    Common.es.Engine.GenericErrorResponse += OnGenericErrorResponse;

    Game Dashboard UI (GameDash.cs):

    Page load event:

    private void GameDash_Load(object sender, EventArgs e)
    {
    if (Common.es.Engine.Connected)
    {
    Common.es.Engine.PluginMessageEvent += OnPluginMessageEvent;
    Common.es.Engine.GenericErrorResponse += OnGenericErrorResponse;
    Common.es.Engine.GetUserCountResponse += OnGetUserCountResponse;
    Common.es.Engine.SessionIdleEvent += OnSessionIdleEvent;
    }

    Please suggest.

  5. #5
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,219
    Thanks
    80
    Thanked 1,087 Times in 1,076 Posts
    In my experience, making ElectroServer static doesn't work. I've always had to make it an object variable and then pass that variable to the other class either in a constructor or a setter, or using a getter from the other class.
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

  6. #6
    Junior Member
    Join Date
    Jun 2012
    Posts
    18
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Hi tcarr,

    Thank you for your suggestion.

    I removed the static ElectroServer object. Also as suggested by you, when i tried the passing the same ElectroServer object from one UI to another UI, it still shows connected but when i try to add event listeners on the second UI, they don't seem to work.

    Following is the code that i tried:

    Login Page UI (Login.cs):

    Calling the second UI (page) constructor,

    GameDash frmGame = new GameDash(es);
    frmGame.ShowDialog();

    Game Dashboard UI (GameDash.cs):

    Fetch the ElectroServer object passed from the first UI (page) as shown above,

    ElectroServer esGB;

    public GameBuilder(ElectroServer es)
    {
    esGB = es;
    InitializeComponent();
    }

    When i use the connected method it shows connected but when i try and add listeners as follows,

    if (esGB.Engine.Connected)
    {
    esGB.Engine.PluginMessageEvent += OnPluginMessageEvent;
    esGB.Engine.GenericErrorResponse += OnGenericErrorResponse;
    }

    The event listeners wont work.

    Please suggest.

  7. #7
    Administrator tcarr's Avatar
    Join Date
    Dec 2007
    Posts
    7,219
    Thanks
    80
    Thanked 1,087 Times in 1,076 Posts
    I don't think I can debug this without reproducing it. Can you create a small project that reproduces the problem, and then send me a zip of it?
    Teresa Carrigan
    Senior Engineer
    Electrotank, Inc.

+ Reply to Thread

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts