Async login not setting ApplicationContext.User with WinForm?

Async login not setting ApplicationContext.User with WinForm?

Old forum URL:

niijyeni posted on Thursday, November 14, 2013

This my code:

        public static void BeginLogin(string account, string password, EventHandler callback)


            var perform = new EventHandler<DataPortalResult<SecurityIdentity>>(delegate(object o, DataPortalResult<SecurityIdentity> e)


                                    if (e.Error == null && e.Object != null)





                                    callback(o, null);



            SecurityIdentity.GetIdentity(account, password, perform);


        private static bool SetPrincipal(IIdentity identity)


            if (identity.IsAuthenticated)


                var principal = new SecurityPrincipal(identity);

                ApplicationContext.User = principal;



            return identity.IsAuthenticated;


If I use asynchronous calls the ApplicationContext.User in the Callback can set up correctly, when you switch to another window ApplicationContext.User reverted to the State is not set.

I've found in the Forum, there are a number of ways, are not handled correctly.And after using the BeginLogin network exceptions will not be caught.

Do you have any good suggestions?


Copyright (c) Marimer LLC