C# visual studio xamarin.forms中的秒表将100ms添加到反应时间测试中

C# visual studio xamarin.forms中的秒表将100ms添加到反应时间测试中,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,因此,我正在使用visual studio xamarin.forms创建一个反应时测试应用程序。我已经完成了我起草的代码,但是,我有一个问题,我的反应时间(根据秒表)比我在其他反应时间测试仪上测试的要大100毫秒。我试着让秒表在按下按钮时停止,而不是点击,但是这对输出时间没有什么影响。以前有没有人见过这样的事情,或者我遗漏了什么?谢谢 这是反应时间测试的xamarin侧 <?xml version="1.0" encoding="utf-8" ?&

因此,我正在使用visual studio xamarin.forms创建一个反应时测试应用程序。我已经完成了我起草的代码,但是,我有一个问题,我的反应时间(根据秒表)比我在其他反应时间测试仪上测试的要大100毫秒。我试着让秒表在按下按钮时停止,而不是点击,但是这对输出时间没有什么影响。以前有没有人见过这样的事情,或者我遗漏了什么?谢谢

这是反应时间测试的xamarin侧

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="ReactionTimeA.ThirdPage">
    <ContentPage.Content>
        <StackLayout Padding="20,35,20,20">
            <Label x:Name="Header_Label"
               Text="When the light turns green remove finger from button"
               FontSize="24"
               Margin="30"
               TextColor="Black"/>
            <Button x:Name="ReactionTimeButton"
                Text="Start Count"
                Pressed="OnButtonClicked"
                WidthRequest="100"
                HeightRequest="100"
                VerticalOptions="Center"
                HorizontalOptions="Center"
                CornerRadius="75"
                BackgroundColor="Blue"
                Margin="30"/>
            <Label x:Name="prereactionLabel"
               Text=""
               TextColor="Black"
               FontSize="12"/>
            <Label x:Name="reactionLabel"
               HorizontalTextAlignment="Center"
               FontSize ="72"
               Text = ""
               TextDecorations = "Underline"
               TextColor="Black"
               Margin="30"/>
        </StackLayout>
    </ContentPage.Content>
</ContentPage>

按钮。当您从按钮上松开手指时,按下的事件将引发。当你按下按钮时,你似乎在寻找一个能被提升的平衡点。您可以通过创建本机渲染器和本机处理相关按钮触摸事件来实现这一点或一种方法,

为什么要启动和停止秒表?只要记下当前时间,最后减去它们。
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Xamarin.Forms;
using Xamarin.Forms.Xaml;

namespace ReactionTimeA
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class ThirdPage : ContentPage
    {

        int button_count = 0;
        Stopwatch stopwatch = new Stopwatch();
        public ThirdPage()
        {
            InitializeComponent();
        }
        public void ReactionTime() {
            Random rand = new Random();
            ReactionTimeButton.IsEnabled = false;
            int time = rand.Next(1000, 10000);
            Task.Delay(time).Wait();
        }
        void OnButtonClicked(object sender, EventArgs e)
        {
            button_count++;

            if (button_count == 1)
            {
                ReactionTimeButton.Text = "Waiting";
                ReactionTime();
                ReactionTimeButton.IsEnabled = true;
                ReactionTimeButton.BackgroundColor = Color.Lime;
                ReactionTimeButton.Text = "Click Now";
                stopwatch.Start();
            }
            else if (button_count == 2)
            {
                stopwatch.Stop();
                int elapsed_time = (int)stopwatch.ElapsedMilliseconds;
                string output_time = Convert.ToString(elapsed_time);
                prereactionLabel.Text = "Your reaction time is:";
                reactionLabel.Text = output_time + "ms";
                button_count = 0;
                stopwatch.Reset();
                ReactionTimeButton.Text = "Start Count";
                ReactionTimeButton.BackgroundColor = Color.Red;
                button_count = 0;
            }
        }
    }
}