应用程序调用Web服务时,Windows资源管理器无响应

时间:2012-03-22 13:47:29

标签: c# .net windows web-services

我有一个作为服务运行的.Net 3.5应用程序。该应用程序有一个调用Web服务的线程,并将该数据存储在SQLite数据库中。

在开发过程中,我们从未遇到任何问题,但在生产环境中,Web服务调用最多需要20秒才能完成。当应用程序调用Web服务并等待回复Windows资源管理器时,因为滞后和无响应。当呼叫返回时,Windows资源管理器再次正常,直到它调用Web服务并等待回复。

进程的CPU使用率非常低,并且在调用Web服务时不会出现峰值。我可以看到硬盘驱动器在写入数据库时​​遇到硬件驱动器但是一切都发生在一瞬间,肯定不会导致速度减慢。

任何帮助都会非常感激,因为我现在对此问题感到茫然。

Machine Specs
Windows XP SP3
Intel core i5 3.2GHz
3.5 GB RAM

代码

public void UpdateMembers()
{
    var moreMembersToUpdate = true;
    while (moreMembersToUpdate)
    {
        var response = GetMembersToUpdate();
        if (response != null)
        {
            UpdateLicense(response.licensed);
            if (response.memberResult == null || response.memberResult.recordsReturned == 0)
                break;
        }
        else
            break;
        UpdateMemberCache(response.memberResult.memberList, response.memberResult.lastUpdate,
            response.memberResult.lastMembersTransactionID);
        moreMembersToUpdate = response.memberResult.recordsLeft;
    }
}

public void UpdateLicense(bool licensed)
{
    var list = DataMapper.GetMapper().QueryForList("Select.License", null);
    if (list != null && list.Count > 0)
    {
        var isLicensed = (Boolean) list[0];
        if(isLicensed != licensed)
        {
            DataMapper.GetMapper().Update("Update.License", licensed);
        }
    }
    else
        DataMapper.GetMapper().Insert("Insert.License", licensed);
}

public StoredValueResponse GetMembersToUpdate()
{
    var token = new OperationToken
    {
        company = Settings.GetCompany(),
        storeID = Settings.GetStoreID(),
        operationID = Guid.NewGuid().ToString(),
        batchSize = 3000,
        password = Settings.GetPassword(),
        userName = Settings.GetCompany()
    };
    var lastSync = GetLastMemberCacheSync();
    return WebMethods.GetUpdatedMemberCache(token, lastSync.TransactionDetailID);
}

public MemberSyncRecord GetLastMemberCacheSync()
{

    var lastMemberSync = DataMapper.GetMapper().QueryForList("Select.LastMemberUpdate", null);
    if (lastMemberSync != null && lastMemberSync.Count > 0 && lastMemberSync[0] != null)
        return (MemberSyncRecord)lastMemberSync[0];
    var record = new MemberSyncRecord
    {
        LastMembersTransactionTime = new DateTime(1900, 1, 1),
        TransactionDetailID = 0
    };
    return record;
}

public void UpdateMemberCache(SmallMemberInfo[] members, DateTime lastSyncTime, long transactionDetailID)
{
    try
    {
        DataMapper.GetMapper().BeginTransaction();
        foreach (var member in members)
        {
            DataMapper.GetMapper().Insert("Insert.MemberInfo", member);
        }
        DataMapper.GetMapper().CommitTransaction();
    }
    catch(Exception)
    {
        DataMapper.GetMapper().RollBackTransaction();
        throw;
    }
    UpdateMemberCacheSyncHistory(lastSyncTime, members.Length, transactionDetailID);
}

0 个答案:

没有答案