Xamarin代码停止运行

时间:2014-08-28 03:36:02

标签: c# android xamarin

我有一个带有便携式库的Xamarin移动程序,我在Android上运行。

我运行以下一段通常运行良好的代码,但有时它似乎“堵塞”并且它到达对远程odata端点执行查询的行然后停止。它不会引发错误,也不会通过错误捕获点和所有代码在调用链中未实现。它只是停止运作。一旦它完成了这一次 - 它将继续永远这样做。我在入境时检查过凭证 - 一切都很好。

应用程序继续运行,好像什么都没发生一样 - 它只是跳过了大量的代码。也没有给出记忆警告。

任何想法都赞赏。

       public async Task<bool> canSetLoggedInPersonWithCredentials_async(System.Net.NetworkCredential credentials)
    {
        if (credentials == null) return false;
        mRemoteEntities.Credentials = credentials;

        DataServiceQuery<Person> query = (DataServiceQuery<Person>)mRemoteEntities.People.Where(c => c.UserName == credentials.UserName );
        TaskFactory<IEnumerable<Person>> tf = new TaskFactory< IEnumerable<Person>>();
        try
        {
            IEnumerable<Person> personLoggedIn = await tf.FromAsync(query.BeginExecute(null, null),
                                       iar => query.EndExecute(iar)); ** STOPS HERE **

            IList<Person> listOfPeople = personLoggedIn.ToList();
            int numberOfPeople = listOfPeople.Count;
            if (numberOfPeople == 0) return false;
            if (numberOfPeople > 1)
            {
                //Error - this should never happen and represents an integrity error in the database
               SystemLogManager.AddErrorToLog(mLocalDataConnection, SystemLogLocation.Library, "Whilst logging in: More than 1 person with the same username", false);

            }
            mLoggedInUser = listOfPeople.ElementAt(0);
           SystemLogManager.addCommentToLog(mLocalDataConnection, SystemLogLocation.Library, "Login was successful");
            return true;

        }
        catch (DataServiceQueryException dsqEx)
        {
            if (dsqEx.InnerException is DataServiceClientException  )
            {
                DataServiceClientException inner =( DataServiceClientException) dsqEx.InnerException;
                if (inner.StatusCode == 401)
                {
                    SystemLogManager.AddErrorToLog(mLocalDataConnection, SystemLogLocation.Library, " Invalid Login credentials" + inner.StatusCode, false);
                }
                else
                {
                    SystemLogManager.AddErrorToLog(mLocalDataConnection, SystemLogLocation.Library, "Login Error: DataServiceClientExceptionData Message: " + inner.Message + " and code " + inner.StatusCode, false);
                }
            }
            else
            {
                SystemLogManager.AddErrorToLog(mLocalDataConnection, SystemLogLocation.Library, "Login Error: DataServiceQueryException Message: " + dsqEx.Message , false);
            }
            return false;
        }

        catch (Exception ex)
        {
            SystemLogManager.AddErrorToLog(mLocalDataConnection, SystemLogLocation.Library, "Login Error: Unknown Exception Message: " + ex.Message, false);
            return false;
        }
    }

0 个答案:

没有答案