CS0029 Невозможно неявно преобразовать тип 'System.Threading.Timer' в 'Windows .UI.Xaml.DispatcherTimer' Это код ошибки, который я получаю, и я считаю, что это причина, по которой я не могу построить свой проект. Мой профессор провел совещание по зуму и сделал видео на YouTube, и это часть кода, который он написал, и мы просмотрели.
namespace DataCollector
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private DispatcherTimer timer;
MeasureLengthDevice measurementDevice = null;
MainViewData displayData = new MainViewData();
Frame frame = null;
MainPage page = null;
public MainPage()
{
this.InitializeComponent();
timer = new Timer(Timer_Tick, null, (int)TimeSpan.FromSeconds(1).TotalMilliseconds,
(int)TimeSpan.FromSeconds(15).TotalMilliseconds);
measurementDevice = new MeasureLengthDevice();
displayData = new MainViewData
{
Measurement = measurementDevice.ToString(),
History = measurementDevice.History
};
}
private void Button_Click(object sender, RoutedEventArgs e)
{
frame = (Frame)Window.Current.Content;
page = (MainPage)frame.Content;
measure.Text = measurementDevice.Measurement.ToString();
measureHistory.Text = measurementDevice.History;
}
private async void Timer_Tick(object state)
{
await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal,
() =>
{
if (page != null)
{
page.measure.Text = measurementDevice.Measurement.ToString();
}
displayData.History = measurementDevice.History;
});
}
}
}