using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Chart130085
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
freq = startFreq;
}
const double startFreq = 200;
const double stepFreq = 10;
const double stopFreq = 560;
double freq = 0;
public void updateGraph(double freq, double amp)
{
if(freq %40 == 0 && freq != startFreq)
{
T1.FoundFrequencies.Add(new ChartPoint { Frequency = freq, Amplitude = 0 });
T1.FoundFrequencies.Add(new ChartPoint { Frequency = freq + stepFreq, Amplitude = 0 });
T1.UnfoundFrequencies.Add(new ChartPoint { Frequency = freq, Amplitude = 0 });
T1.UnfoundFrequencies.Add(new ChartPoint { Frequency = freq + stepFreq, Amplitude = 0 });
}
else
{
T1.FoundFrequencies.Add(new ChartPoint { Frequency = freq, Amplitude = amp });
T1.FoundFrequencies.Add(new ChartPoint { Frequency = freq + stepFreq, Amplitude = amp });
T1.UnfoundFrequencies.Add(new ChartPoint { Frequency = freq, Amplitude = double.NaN });
T1.UnfoundFrequencies.Add(new ChartPoint { Frequency = freq + stepFreq, Amplitude = double.NaN });
}
}
private void btnStep_Click(object sender, RoutedEventArgs e)
{
while (freq <= stopFreq)
{
double amp = freq * 3 / 12;
updateGraph(freq, amp);
Thread.Sleep(500);
freq += stepFreq;
}
}
}
public class ChartPoint
{
public double Frequency { get; set; }
public double Amplitude { get; set; }
}
public class ChartPoints
{
public ObservableCollection<ChartPoint> FoundFrequencies { get; set; }
public ObservableCollection<ChartPoint> UnfoundFrequencies { get; set; }
public void Clear()
{
FoundFrequencies.Clear();
UnfoundFrequencies.Clear();
}
public ChartPoints()
{
FoundFrequencies = new ObservableCollection<ChartPoint>();
UnfoundFrequencies = new ObservableCollection<ChartPoint>();
}
}
}
public partial class MainWindow : Window
{
DispatcherTimer timer;
public MainWindow()
{
InitializeComponent();
timer = new DispatcherTimer();
timer.Interval = new TimeSpan(0, 0, 0, 0, 500);
timer.Tick += Timer_Tick;
}
private void Timer_Tick(object sender, EventArgs e)
{
if(freq <= stopFreq)
{
double amp = freq * 3 / 12;
updateGraph(freq, amp);
freq += stepFreq;
}
}
private void btnStep_Click(object sender, RoutedEventArgs e)
{
timer.Start();
}
} |
private async void btnStep_Click(object sender, RoutedEventArgs e)
{
while(freq <= stopFreq)
{
double amp = freq * 3 / 12;
updateGraph(freq, amp);
await Task.Delay(500);
freq += stepFreq;
}
}
|
async void mainFunc()
{
for (int i = 0; i < frequencies.Count; i++)
{
}
await Task.Delay(500);
}
|