2

我正在尝试在收益返回后执行代码。我有调用另一种方法的WebMethod,我想在将值返回给WebMethod(执行方法setNextCampaign())后做一些工作这是我的代码:

[WebMethod]
public long NextCall(long UserID)
{
    CampaignManagerExtended cacheCampaignManager = fillCampaignManager(false);

    return cacheCampaignManager.NextCall(UserID).First();
}



public IEnumerable<long> NextCall(long UserID)
        {
            UserExtended ue = null;
            try
            {
                if (!CacheUsers.ContainsKey(UserID))
                    AddUser(UserID);

                ue = CacheUsers.First(p => p.Key == UserID).Value;
                if (ue.NextCampaign != null)
                {
                    QueueItemPersonal qp = ue.NextFromPersonalQueue();
                    if (qp != null)
                    {

                        yield return qp.CampaignPersonID;
                    }
                    else 
                    { 
                        QueueItemScheduled qs = ue.NextCampaign.NextFromScheduleQueue();
                        if (qs != null)
                        {

                            yield return qs.CampaignPersonID;
                        }
                        else 
                        { 
                            QueueItemGeneral qg = ue.NextCampaign.NextFromGeneralQueue();
                            if (qg != null)
                            {

                                yield return qg.CampaignPersonID;
                            }                  
                            else
                                 yield return 0;
                        }
                    }
                    ue.NextCampaign.fillGeneralQueue();
                    ue.setNextCampaign();
                }
                else
                    yield return 0;

            }
            //catch
            //{
            //    yield return 0;
            //}
            finally
            {

            }
        }

有任何想法吗?

4

2 回答 2

5

而不是这个

<some stuff>;
yield return <something>;
<some epilog stuff that should be executed after yield>

做这个:

try
{
  <some stuff>;
  yield return <something>;
}
finally
{
  <some epilog stuff that should be executed after yield>
}
于 2013-09-06T09:45:43.980 回答
2

只需保存产量,直到您准备好退货:

[WebMethod]
public long NextCall(long UserID)
{
    CampaignManagerExtended cacheCampaignManager = fillCampaignManager(false);

    return cacheCampaignManager.NextCall(UserID).First();
}

public IEnumerable<long> NextCall(long UserID)
{
    int returnID;
    UserExtended ue = null;

    try
    {
        if (!CacheUsers.ContainsKey(UserID))
        {
            AddUser(UserID);
        }

        ue = CacheUsers.First(p => p.Key == UserID).Value;

        if (ue.NextCampaign != null)
        {
            QueueItemPersonal qp = ue.NextFromPersonalQueue();

            if (qp != null)
            {
                returnID =  qp.CampaignPersonID;
            }
            else 
            { 
                QueueItemScheduled qs = ue.NextCampaign.NextFromScheduleQueue();

                if (qs != null)
                {
                    returnID  = qs.CampaignPersonID;
                }
                else 
                { 
                    QueueItemGeneral qg = ue.NextCampaign.NextFromGeneralQueue();

                    if (qg != null)
                    {
                        returnID = qg.CampaignPersonID;
                    }                  
                    else
                    {
                         returnID = 0;
                    }
                }
            }

            ue.NextCampaign.fillGeneralQueue();
            ue.setNextCampaign();
        }
        else
        {
            returnID = 0;
        }

        yield return returnID;
    }
    //catch
    //{
    //    yield return 0;
    //}
    finally
    {

    }
}
于 2013-09-06T09:47:55.257 回答