Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何从“开始”;x";计时器中的秒数_C#_Asp.net - Fatal编程技术网

C# 如何从“开始”;x";计时器中的秒数

C# 如何从“开始”;x";计时器中的秒数,c#,asp.net,C#,Asp.net,我想打开我的表格,计时器从10秒开始,然后是11秒,然后是12秒,以此类推 代码: 公共静态秒表; swTimer=新秒表(); SwTimer=10; swTimer.Start(); 执行此操作的简单方法???您不能强制秒表在指定时间启动。 但是,在测量经过的时间时,只需添加10000毫秒 Stopwatch swTimer = new Stopwatch(); swTimer.Start(); //Do stuff swTimer.Stop(); //Elapsed seconds,

我想打开我的表格,计时器从10秒开始,然后是11秒,然后是12秒,以此类推

代码:

公共静态秒表;
swTimer=新秒表();
SwTimer=10;
swTimer.Start();

执行此操作的简单方法???

您不能强制秒表在指定时间启动。 但是,在测量经过的时间时,只需添加10000毫秒

Stopwatch swTimer = new Stopwatch();
swTimer.Start();
//Do stuff
swTimer.Stop();

//Elapsed seconds, rounding down to the nearest second.
int seconds = (swTimer.ElapsedMilliseconds + 10000) / 1000;
或者,如果你使用秒,你可以加10秒

Stopwatch swTimer = new Stopwatch();
swTimer.Start();
//Do stuff
swTimer.Stop();

//Elapsed seconds, rounding down to the nearest second.
int seconds = (swTimer.ElapsedMilliseconds / 1000) + 10;

编辑:如果您试图将时间限制在特定的时间范围内,则可能需要使用计时器(如秒表,但会下降。)

您无法强制秒表在指定的时间启动。 但是,在测量经过的时间时,只需添加10000毫秒

Stopwatch swTimer = new Stopwatch();
swTimer.Start();
//Do stuff
swTimer.Stop();

//Elapsed seconds, rounding down to the nearest second.
int seconds = (swTimer.ElapsedMilliseconds + 10000) / 1000;
或者,如果你使用秒,你可以加10秒

Stopwatch swTimer = new Stopwatch();
swTimer.Start();
//Do stuff
swTimer.Stop();

//Elapsed seconds, rounding down to the nearest second.
int seconds = (swTimer.ElapsedMilliseconds / 1000) + 10;

编辑:如果您试图将时间限制在特定的时间范围内,则可能需要使用计时器(如秒表,但会下降。)

Timer.aspx

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server"></asp:Label> seconds passed.
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"></asp:AsyncPostBackTrigger>
            </Triggers>
        </asp:UpdatePanel>
</form>

Timer.aspx

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick"></asp:Timer>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:Label ID="Label1" runat="server"></asp:Label> seconds passed.
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick"></asp:AsyncPostBackTrigger>
            </Triggers>
        </asp:UpdatePanel>
</form>

为什么不在显示计时器时加上10秒?你所说的10、11、12秒是什么意思。。。?您想在打开表单时从10秒开始启动计时器?
typeof(Stopwatch).GetField(“\u appeased”,bindingsflags.NonPublic).SetValue(swTimer,10*10000*1000)
有关相关数学,请参阅@gurkan Yes,从10秒开始启动计时器,只需每秒增加1秒。@gurkan我使用asp.net,在我的form.cs.中,为什么不在显示计时器时加上10秒?你所说的10、11、12秒是什么意思。。。?您想在打开表单时从10秒开始启动计时器?
typeof(Stopwatch).GetField(“_appeased”,bindingsflags.NonPublic).SetValue(swTimer,10*10000*1000)
有关相关数学,请参阅@gurkan Yes,从10秒开始启动计时器,只需每秒增加1秒。@gurkan我使用asp.net,在my form.cs中。