|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
我见过java运行在手机上,包括很廉价的山寨手机,但是却暂时没发现.net在手机上有什么作为。wp7可能是个转机,但是按照《Java的跨平台就是一句谎言。那.net的跨平台也当之无愧是一句谎言。asp.net|web|技能网上已有良多Web进度条的例子,可是良多都是预算工夫,不克不及正真反响义务的实在进度。我本人分离多线程和ShowModalDialog制做了一个及时进度条,道理很复杂:利用线程入手下手长工夫的义务,界说一个Session,当义务举行到分歧的阶段改动Session的值,线程入手下手的同时利用ShowModalDialog翻开一个进度条窗口,不休革新这个窗口猎取Session值,反响出及时的进度。上面就来看看详细的代码:(文章开头处下载源代码)
先新建一个Default.aspx页面,
客户端代码:
<bodyMS_POSITIONING="GridLayout">
<formid="Form1"method="post"runat="server">
<br>
<br>
<asp:Buttonid="Button1"runat="server"Text="StartLongTask!"></asp:Button>
</form>
</body>
服务器端代码:
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;
usingSystem.Text;
namespaceWebProgressBar
{
/**////<summary>
///Summarydescriptionfor_Default.
///</summary>
publicclass_Default:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.ButtonButton1;
privatevoidPage_Load(objectsender,System.EventArgse)
{
//Putusercodetoinitializethepagehere
}
WebFormDesignergeneratedcode#regionWebFormDesignergeneratedcode
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:ThiscallisrequiredbytheASP.NETWebFormDesigner.
//
InitializeComponent();
base.OnInit(e);
}
/**////<summary>
///RequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththecodeeditor.
///</summary>
privatevoidInitializeComponent()
{
this.Button1.Click+=newSystem.EventHandler(this.Button1_Click);
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion
privatevoidLongTask()
{
//摹拟长工夫义务
//每一个轮回摹拟义务举行到分歧的阶段
for(inti=0;i<11;i++)
{
System.Threading.Thread.Sleep(1000);
//设置每一个阶段的state值,用来显现以后的进度
Session["State"]=i+1;
}
//义务停止
Session["State"]=100;
}
publicstaticvoidOpenProgressBar(System.Web.UI.PagePage)
{
StringBuildersbScript=newStringBuilder();
sbScript.Append("<scriptlanguage=JavaScripttype=text/javascript>
");
sbScript.Append("<!--
");
//必要IE5.5以上撑持
sbScript.Append("window.showModalDialog(Progress.aspx,,dialogHeight:100px;dialogWidth:350px;edge:Raised;center:Yes;help:No;resizable:No;status:No;scroll:No;);
");
//IE5.5以下利用window.open
//sbScript.Append("window.open(Progress.aspx,,height=100,width=350,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no);
");
sbScript.Append("//-->
");
sbScript.Append("</script>
");
Page.RegisterClientScriptBlock("OpenProgressBar",sbScript.ToString());
}
privatevoidButton1_Click(objectsender,System.EventArgse)
{
System.Threading.Threadthread=newSystem.Threading.Thread(newSystem.Threading.ThreadStart(LongTask));
thread.Start();
Session["State"]=1;
OpenProgressBar(this.Page);
}
}
}
新建一个进度条页面Progress.aspx
客户端:
在head中到场<basetarget="_self">
<bodyMS_POSITIONING="GridLayout">
<formid="Form1"method="post"runat="server">
<asp:Labelid="lblMessages"runat="server"></asp:Label>
<asp:Panelid="panelBarSide"runat="server"Width="300px"BorderStyle="Solid"BorderWidth="1px"
ForeColor="Silver">
<asp:Panelid="panelProgress"runat="server"Width="10px"BackColor="Green"></asp:Panel>
</asp:Panel>
<asp:Labelid="lblPercent"runat="server"ForeColor="Blue"></asp:Label>
</form>
</body>
服务器端:
usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Web;
usingSystem.Web.SessionState;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Web.UI.HtmlControls;
namespaceWebProgressBar
{
/**////<summary>
///SummarydescriptionforProgress.
///</summary>
publicclassProgress:System.Web.UI.Page
{
protectedSystem.Web.UI.WebControls.LabellblMessages;
protectedSystem.Web.UI.WebControls.PanelpanelProgress;
protectedSystem.Web.UI.WebControls.PanelpanelBarSide;
protectedSystem.Web.UI.WebControls.LabellblPercent;
privateintstate=0;
privatevoidPage_Load(objectsender,System.EventArgse)
{
//Putusercodetoinitializethepagehere
if(Session["State"]!=null)
{
state=Convert.ToInt32(Session["State"].ToString());
}
else
{
Session["State"]=0;
}
if(state>0&&state<=10)
{
this.lblMessages.Text="Taskundertaking!";
this.panelProgress.Width=state*30;
this.lblPercent.Text=state*10+"%";
Page.RegisterStartupScript("","<script>window.setTimeout(window.Form1.submit(),100);</script>");
}
if(state==100)
{
this.panelProgress.Visible=false;
this.panelBarSide.Visible=false;
this.lblMessages.Text="TaskCompleted!";
Page.RegisterStartupScript("","<script>window.close();</script>");
}
}
WebFormDesignergeneratedcode#regionWebFormDesignergeneratedcode
overrideprotectedvoidOnInit(EventArgse)
{
//
//CODEGEN:ThiscallisrequiredbytheASP.NETWebFormDesigner.
//
InitializeComponent();
base.OnInit(e);
}
/**////<summary>
///RequiredmethodforDesignersupport-donotmodify
///thecontentsofthismethodwiththecodeeditor.
///</summary>
privatevoidInitializeComponent()
{
this.Load+=newSystem.EventHandler(this.Page_Load);
}
#endregion
}
}
它有很多缺点的,有兴趣可以到网上去搜索一下。于是微软有发明了“下一代”C++:C++/CLI语言,这个可以解决在.NETFramework中,托管C++产生的问题。在《程序员》杂志上,lippman和李建中合作连载介绍了C++/CLI语言。 |
|