首页 新闻 会员 周边 捐助

asp/asp.net下运行exe文件出现的一个奇怪问题

0
悬赏园豆:20 [已关闭问题]

最近一个项目中,需要在asp/asp.net调用外部exe文件,代码测试无误后,部署到server(window server 2003)上,发现速度非常慢,执行时间一般14秒左右,同样的程序在beta环

境(window server 2003)和本机(windows xp professional)上执行很快 速度是300毫秒以内,我感觉非常奇怪,尝试了很多设置,问题还是不能解决,
我想应该不是权限的问题,如果是权限问题,结果应该是要么能够执行要么不能,现在的结果能执行,但是就是非常慢。

请csdn的朋友给些建议或思路 非常感谢!

在asp/asp.net情况都是如此,下面我把code,展示给大家,请予以诊断分析!

[b]asp.net
=====================================================================================================================================
===[/b]

    /// <summary>
    ///
    /// </summary>
    /// <param name="sender"> </param>
    /// <param name="e"> </param>
    protected void btnCheckAndGetTag_Click(object sender, EventArgs e)
    {
        if ((txtRevisionId.Text.Trim().Length <= 0) ||
            (txtSourceCode.Text.Trim().Length <= 0))
        {
            return;
        }

        string strResult = string.Empty;
        string currenttag = GetTagByReversionIdFromSvnServer(txtSourceCode.Text.Trim(), txtRevisionId.Text.Trim());
        if (!string.IsNullOrEmpty(currenttag))
        {
            strResult = "Current Tag=" + currenttag + " <Br/>";
            bool bCheck = CheckDeliveryTagByProjectIDAndTag(currenttag.Replace("\'", ""), txtSourceCode.Text.Trim(), txtRevisionId.Text.Trim());
            if (bCheck)
            {
                strResult += "根据Revision id获取的tag在project delivery中已经存在 <Br/>";
            }
            else
            {
                strResult += "根据Revision id获取的tag在project delivery中不存在 <Br/>";
            }
        }
        else
        {
            strResult += "根据Revision id没有获取相应的tag <Br/>";
        }
        lblMessage.Text = strResult;
    }


    /// <summary>
    ///
    /// </summary>
    /// <param name="ReversionId"> </param>
    /// <returns> </returns>
    protected string GetTagByReversionIdFromSvnServer(string SourceCodePath, string ReversionId)
    {
        DateTime dt1 = DateTime.Now;
        StringBuilder sbCommand = new StringBuilder();
        sbCommand.Append(@"cd /d " + SvnExePath + System.Environment.NewLine);
        sbCommand.Append(@"svn.exe log " + SourceCodePath + " -r" + ReversionId + " --xml --username " + SvnExeUser + " --password " + SvnExeUserPassword +

"|find \"msg\"" + System.Environment.NewLine);
        sbCommand.Append(@"exit" + System.Environment.NewLine);

        string result = RunSvnCommandRight(sbCommand.ToString().Trim()); // 调用的函数在下面

        DateTime dt2 = DateTime.Now;
        TimeSpan ts = dt2 - dt1;
        string executeTime = string.Format("{0}时{1}分{2}秒{3}毫秒", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds);
        Response.Write("Execute svn.exe command time=" + executeTime);


        DateTime dt3 = DateTime.Now;
        string[] folders = Regex.Split(result, @"\r\n");
        StringBuilder sbResult = new StringBuilder();
        string strResult = string.Empty;

        if (folders != null && folders.Length > 0)
        {
            for (int i = 0; i < folders.Length; i++)
            {
                if ((folders[i].IndexOf(" <msg>") >= 0) ||
                    (folders[i].IndexOf(" </msg>") >= 0))
                {
                    sbResult.Append(folders[i]);
                }
            }
        }

        string strReturn = string.Empty;
        strResult = sbResult.ToString();
        if (!string.IsNullOrEmpty(strResult))
        {
            strReturn=strResult.Substring(0, strResult.Length - 6).Substring(5);
        }

        DateTime dt4 = DateTime.Now;
        TimeSpan ts1 = dt4 - dt3;
        string executeTime2 = string.Format("{0}时{1}分{2}秒{3}毫秒", ts1.Hours, ts1.Minutes, ts1.Seconds, ts1.Milliseconds);
        Response.Write(" <br/>");
        Response.Write("String process and return value time=" + executeTime2);

        return strReturn;
    }

   
    /// <summary>
    /// 运行脚本命令
    /// </summary>
    /// <param name="strCommand"> </param>
    /// <returns> </returns>
    protected string RunSvnCommandRight(string strCommand)
    {
        if (string.IsNullOrEmpty(strCommand))
        {
            return string.Empty;
        }

        StreamWriter sIn = null;
        StreamReader sOut = null;

        ProcessStartInfo psi = new ProcessStartInfo("cmd.exe");
        psi.UseShellExecute = false;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardInput = true;
        psi.RedirectStandardError = true;
        psi.CreateNoWindow = true;
        try
        {
            Process process = Process.Start(psi);
            sOut = process.StandardOutput;
            sIn = process.StandardInput;
            sIn.WriteLine(strCommand);
            process.Close();
            return sOut.ReadToEnd();
        }
        catch (Exception e)
        {
            return string.Empty;
        }
        finally
        {
            if (sIn != null)
            {
                sIn.Close();
            }
            if (sOut != null)
            {
                sOut.Close();
            }
        }

        return string.Empty;
    }


asp
==============================================================================================================

<%
Response.Clear()
'初始化执行svn.exe命令的几个参数
dim svnExePath,SvnExeUser,SvnExeUserPassword
svnExePath="C:\Program Files\CollabNet Subversion Client"
SvnExeUser="batuser"
SvnExeUserPassword="cqf3Qfyw5J"
%>
<html>
<head>
<title>根据Revision ID和code path 获取tag </title>
</head>
<body>
<%

if(trim(request.form("btnSubmit"))="提交") then
dim strCodePath,strRevisionId

strCodePath=trim(Request.Form("txtCodePath"))
strRevisionId=trim(Request.Form("txtRevisionId"))

'检测输入
if(len(strCodePath) <=0) then
Response.Write("请输入Source code path!")
Response.End()
end if
if(len(strRevisionId) <=0) then
Response.Write("请输入Revision Id!")
Response.End()
end if

strTag=GetTagByReversionIdFromSvnServer(strCodePath,strRevisionId)
Response.write("Current tag=" & strTag & " <br/>")
end if
%>
<form id="form1" name="form1" action="checktag_dmss.asp" method="post">
<table id="table1" cellspacing="1" cellpadding="1" border="1" style="width:98%">
<tr>
<td style="width:20%;text-align:center">Revision ID: </td>
<td style="width:80%;text-align:left"> <input type="text" id="txtRevisionId" name="txtRevisionId" size="60" maxlength="100"/> </td>
</tr>
<tr>
<td style="width:20%;text-align:center">Source code path: </td>
<td style="width:80%;text-align:left"> <input type="text" id="txtCodePath" name="txtCodePath" size="60" maxlength="100"/> </td>
</tr>
<tr>
<td colspan="2">
<input type="submit" id="btnSubmit" name="btnSubmit" value="提交" style="width:90px;height:25px">&nbsp;&nbsp;
<input type="reset" id="btnReset" name="btnReset" value="重置" style="width:90px;height:25px">
</td>
</tr>
</table>
</form>
</body>
</html>

<%
    Function GetTagByReversionIdFromSvnServer(SourceCodePath,ReversionId)
        '检测参数
if ((isnull(SourceCodePath)=true) or (len(SourceCodePath)=0) or (isnull(ReversionId)=true) or (len(ReversionId)=0)) then
GetTagByReversionIdFromSvnServer=""
Exit Function
End if

'需要执行命令行
        strCommand="svn.exe log "&SourceCodePath&" -r"&ReversionId&" --xml --username "&SvnExeUser&" --password "&SvnExeUserPassword&"|find" & space(1) & chr(34) & "msg" & chr(34)

'统计开始与结束时间 统计执行花费时间
dim startDateTime,endDateTime,diffDateTime
startDateTime=now()
        strResult = RunSvnExeCommand(strCommand)
        endDateTime=now()
       
        diffDateTime = DateDiff("s",startDateTime,endDateTime)
Response.Write("执行svn.exe命令花费时:" & Int(diffDateTime/3600) & "小时" & Int(diffDateTime/60) Mod 60 & "分钟" & diffDateTime Mod 60 & "秒 <br/>")

        if ((IsNull(strResult)=true) or (len(strResult) <=0)) then
GetTagByReversionIdFromSvnServer=""
Exit Function
        end if
       
       
        dim arrResult,strResults,strReturn
        strResults=""
        arrResult=split(strResult," <br>")
        for i=Lbound(arrResult) to UBound(arrResult)
if((Instr(arrResult(i)," <msg>")>0) or (Instr(arrResult(i)," </msg>")>0)) then
strResults=strResults+arrResult(i)
end if
        next
       
        if((IsNull(strResults)=false) and (len(strResults))>0) then
        strReturn=Mid(strResults,6,len(strResults)-6)
        end if
       
        GetTagByReversionIdFromSvnServer=strReturn
    End Function
   
    '执行svn.exe命令的函数
    Function RunSvnExeCommand(strComm)
    '检测参数
if ((isnull(strComm)=true) or (len(strComm)=0)) then
RunSvnExeCommand=""
Exit Function
End if

Set objWShell = CreateObject("WScript.Shell")
Set objCmd = objWShell.Exec("cmd.exe")
objCmd.StdIn.WriteLine "cd /d " & svnExePath
objCmd.StdIn.WriteLine strComm
objCmd.StdIn.WriteLine "exit"
strPResult = objCmd.StdOut.Readall()
set objCmd = nothing
Set objWShell = nothing
RunSvnExeCommand=replace(strPResult,vbCrLf," <br>") 
    End Function
%>

Eric_Gq_Liu的主页 Eric_Gq_Liu | 初学一级 | 园豆:180
提问于:2009-10-23 08:14
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册