locked
Method in a web service runs multiple times (depending on the button click) RRS feed

  • Question

  • User364521 posted

    I am consuming a method in a web service soap. It runs smoothly when the button is being tapped once, -> Dialog box shows up once -> Clicks OK -> Dialog box exits, button is being tapped twice -> Dialog box shows up twice -> Clicks OK twice coz of 2 dialog boxes that showed up -> Dialog boxes exits, button is being tapped thrice -> Dialog box shows up thrice -> Clicks OK thrice coz of 3 dialog boxes that showed up -> Dialog boxes exits ...and so on.. TIA.

    case Resource.Id.btnLogin:
    
                hud = KK.Create(this.Activity)
                     .SetSize(75, 75);
                hud.Show();
    
                loginClick(); //Function for button click
    
                break;
    
    
    private void loginClick(){
           hud.Dismiss();
           if (TextUtils.IsEmpty(txtID.Text.ToString()) || TextUtils.IsEmpty(txtPass.Text.ToString()))
           {
               AlertMessageView.showAlertDialog(this.Activity, "Error", GetString(Resource.String.Msg33), "OK", null, null, null);
           }
           else if (txtID.Text.ToString().Trim().Length < 12)
           {
                tilID.Error = GetString(Resource.String.Msg8);
           }
           else
           { 
               service.VerifyLoginAsync("user", "password", txtID.Text.ToString(), txtPass.Text.ToString());
               service.VerifyLoginCompleted += Service_VerifyLoginCompleted;
           }
       }
    

    Consuming web service method Verify Login:

    private void Service_VerifyLoginCompleted(object sender, IDWebService.VerifyLoginCompletedEventArgs e)
       {
    
        if (e.Result.isValid == true)
        {
            #region firstLogin
            if (e.Result.isfirstlogin == "1")
            {
                Console.WriteLine("Redirect Verification page");
    
                AlertMessageView.showAlertDialog(this.Activity, "Invalid login", "Is it your first time to login?", "YES", "NO", dialogFTL, null);
    
            }
            else
            {
                #region lockedout
                if (e.Result.islockedout == "1")
                {
                    AlertMessageView.showAlertDialog(this.Activity, "Account has been locked", "Kindly coordinate with employer", "OK", null, null, null);
    
                }
    
                else {
    
                    #region forgotPass
                    if (e.Result.isforgotpass == "1")
                    {
                        AlertMessageView.showAlertDialog(this.Activity, "Invalid Password", "Please change your password.", "YES", "CANCEL", dialogFTL, null);
    
                    }
                    else
                    {
                        #region enabled
                        if (e.Result.isenabled == "1")
                        {
                            #region validpass
                            if (e.Result.isValidPassword == true)
                            {
    
                                fname = e.Result.fname;
                                number = e.Result.number;
                                GenerateOTP();
    
                                var intent = new Intent(this.Activity, typeof(OTPLoginActivity));
                                StartActivity(intent);
                                Activity.Finish();
                            }
                            else
                            {
                                Console.WriteLine("Failed Date Login");
                                #region morethan24
                                if (e.Result.isMoreThan24Hrs == true)
                                {
    
                                    loginCounter = 0;
                                    MemberFailedLogin(loginCounter.ToString());
                                }
                                else
                                {
                                    loginCounter = Convert.ToInt32(e.Result.failedattempt) + 1;
    
                                    if (loginCounter < 3)
                                    {
                                        MemberFailedLogin(loginCounter.ToString());
                                    }
                                    else
                                    {
                                        Console.WriteLine("Account has been locked" + loginCounter);
    
                                        MemberLockAccount();
                                        AlertMessageView.showAlertDialog(this.Activity, "Account has been locked", "Kindly coordinate with employer.", "OK", null, null, null);
                                    }
                                }
                                #endregion
    
                            }
                            #endregion 
                        }
                        else
                        {
    
                            AlertMessageView.showAlertDialog(this.Activity, "Account disabled", "Please contact your employer.", "OK", null, null, null);
    
                        }
                        #endregion
    
                    }
                    #endregion
                }
                #endregion
    
            }
            #endregion
        }
        else
        {
            AlertMessageView.showAlertDialog(this.Activity, null, "Invalid Credentials", "OK", null, null, null);
    
        }
    }
    
    Wednesday, January 9, 2019 1:32 AM

All replies

  • User355485 posted

    You need to avoid rapidly click on a button Sample:

    bool _userTapped; Public void ButtonEvent(object sender,EventArgs e) { if(_userTapped) return; // your code //... _userTapped=false; }

    Wednesday, January 9, 2019 6:01 AM
  • User359363 posted

    You could add the effective time for your button click event. Only the first click is valid for multiple clicks within 3 seconds:

    public static int MIN_CLICK_DELAY_TIME = 3000;//the effective time
    private long lastClickTime = 0;
    

    public void ShortAlert(string message) {
    long currentTime = Calendar.Instance.TimeInMillis; if (currentTime - lastClickTime > MIN_CLICK_DELAY_TIME) { lastClickTime = currentTime; //execute your method
    }
    }

    Thursday, January 10, 2019 2:23 AM
  • User364521 posted

    @Harshita , @YorkGo - I already fix the error of multiple dialog box, but when I put a break point on a certain code, it still runs on it multiple times. I tried also your suggestions but still the same :(

    Thursday, January 10, 2019 3:10 AM
  • User359363 posted

    @kmmpaliza , when you put a break point on your code, the time interval between two click event will be more longer then MIN_CLICK_DELAY_TIME, that's why it didn't work.

    Thursday, January 10, 2019 5:10 AM
  • User359363 posted

    @kmmpaliza , have you resolved this issue or is there anything we can help with?

    Monday, January 14, 2019 2:10 AM
  • User364521 posted

    @YorkGo Not yet.

    Friday, January 18, 2019 9:15 AM
  • User359363 posted

    @kmmpaliza , what is your problem now?

    Friday, January 18, 2019 9:51 AM
  • User364521 posted

    @YorkGo I think, the web service itself called multiple times, because even I put delay in button and enabled and disabled it still the web service method called multiple times.

    Wednesday, January 23, 2019 2:24 AM