SL Async callback called twice...but only in Release mode

SL Async callback called twice...but only in Release mode

Old forum URL: forums.lhotka.net/forums/t/10420.aspx


Gort posted on Tuesday, June 07, 2011

I have a Silverlight callback that is being called twice but this only occurs when running in Release mode.  When running in Debug mode, things work as expected.  My code is as follows:

private void Login()
{
  StaffLogin.LoginAsync(UserName, Password, LoginCompleted);
}

private void LoginCompleted(object sender, DataPortalResult<StaffLogin> e)
{

   ....... 

CSLA Object Code (StaffLogin.cs):

public static void LoginAsync(System.String userName, System.String password, EventHandler<DataPortalResult<StaffLogin>> handler)
{
  var criteria = new StaffCriteria { StaffLogin = userName, StaffPassword = password };

  var dp = new DataPortal<StaffLogin>();
  dp.FetchCompleted += handler;
  dp.BeginFetch(criteria);
}

My DataPortal_Fetch method is very simple in that is just calls a stored proc and returns an object with a few properties. 

I have littered my code with MessageBox alerts to see what is being called and the async call is only occurring once, but the callback is being called twice.  Again, this ONLY occurs when running in Release mode.

Any ideas?

Tks.

JonnyBee replied on Tuesday, June 07, 2011

The only thing that comes to mind is if the dp.FethCompleted += get set twice - that would cause the callback to be called twice.

Do you use any compile directives as to what code is called in Debug vs Release mode?

Gort replied on Tuesday, June 07, 2011

No compile directives in the code related to anything regarding this area.

The FetchCompleted is only being set once, here is that code:

public static void LoginAsync(System.String userName, System.String password, EventHandler<DataPortalResult<StaffLogin>> handler)
{
    var encoding = new UTF8Encoding();
    var criteria = new StaffCriteria { StaffLogin = userName, StaffPassword = encoding.GetBytes(password) };

    var dp = new DataPortal<StaffLogin>();
    dp.FetchCompleted += handler;
    dp.BeginFetch(criteria);
}

JonnyBee replied on Tuesday, June 07, 2011

Could you add code to write the callstack to a tracefile or Trace output in the FetchCompleted handler.

This should hopefully reveal where the call originates from.

Gort replied on Tuesday, June 07, 2011

I compared the stack trace at the time the callback handler is called and the trace is the same for both.

Copyright (c) Marimer LLC