This is a migrated thread and some comments may be shown as answers.

asyncronous save

1 Answer 34 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Suraj
Top achievements
Rank 1
Suraj asked on 18 Jan 2012, 02:46 PM
i am using the following code to save the data.

button click()
{
clientLeave.SaveLeaveApplicationCompleted += new EventHandler<SaveLeaveApplicationCompletedEventArgs>(clientLeave_SaveLeaveApplicationCompleted1);
                clientLeave.SaveLeaveApplicationAsync(item);
}

void clientLeave_SaveLeaveApplicationCompleted1(object sender, SaveLeaveApplicationCompletedEventArgs e)
        {
            if (e.Result > -1)
            {
               
                    MessageBox.Show("Record Saved Successfully", Declares.MsgTitle, MessageBoxButton.OK);
 
            }
        }

Note:
If i save the second record, message box is showing twice & thrice for 3rd record and so on...

1 Answer, 1 is accepted

Sort by
0
Stanescu Mihai
Top achievements
Rank 1
answered on 06 Feb 2012, 11:31 AM
Haven't tried it but I think your problem is that you don't unsubscribe from the SaveLeaveApplicationCompleted event, and every time you save again it subscribes again and again.
Try putting this to unsubsribe from the event:
clientLeave.SaveLeaveApplicationCompleted -= new EventHandler<SaveLeaveApplicationCompletedEventArgs>(clientLeave_SaveLeaveApplicationCompleted1); 
   in the body of void clientLeave_SaveLeaveApplicationCompleted1 ().
Either this or subscribe to the SaveLeaveApplicationCompleted event outside of the button click.
Tags
General Discussions
Asked by
Suraj
Top achievements
Rank 1
Answers by
Stanescu Mihai
Top achievements
Rank 1
Share this question
or