Created
July 6, 2021 09:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Windows; | |
using System.Windows.Threading; | |
namespace WpfApp1 | |
{ | |
/// <summary> | |
/// Interaction logic for App.xaml | |
/// </summary> | |
public partial class App : Application | |
{ | |
private readonly MainWindow _mainWindow; | |
private readonly BookingWindows _bookingWindow; | |
private readonly DispatcherTimer _dispatcherTimer; | |
private readonly TimeSpan _start = new TimeSpan(7, 30, 0); | |
private readonly TimeSpan _end = new TimeSpan(16, 30, 0); | |
public App() | |
{ | |
_mainWindow = new MainWindow(); | |
_mainWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; | |
_mainWindow.SourceInitialized += (s, a) => _mainWindow.WindowState = WindowState.Maximized; | |
_bookingWindow = new BookingWindows(); | |
_bookingWindow.WindowStartupLocation = WindowStartupLocation.CenterScreen; | |
_bookingWindow.SourceInitialized += (s, a) => _bookingWindow.WindowState = WindowState.Maximized; | |
_dispatcherTimer = new DispatcherTimer(); | |
_dispatcherTimer.Interval = TimeSpan.FromSeconds(1); | |
_dispatcherTimer.Tick += _dispatcherTimer_Tick; | |
_mainWindow.Closed += window_Closed; | |
_bookingWindow.Closed += window_Closed; | |
} | |
private void window_Closed(object sender, EventArgs e) | |
{ | |
Current.Shutdown(); | |
} | |
private void _dispatcherTimer_Tick(object sender, EventArgs e) | |
{ | |
var timeOfDay = DateTime.Now.TimeOfDay; | |
if (timeOfDay >= _start && timeOfDay <= _end) | |
//if (timeOfDay.Minutes % 2 == 0) | |
{ | |
if (!_mainWindow.IsVisible) | |
{ | |
_mainWindow.Show(); | |
} | |
if (_bookingWindow.IsVisible) | |
{ | |
_bookingWindow.Hide(); | |
} | |
} | |
else | |
{ | |
if (!_bookingWindow.IsVisible) | |
{ | |
_bookingWindow.Show(); | |
} | |
if (_mainWindow.IsVisible) | |
{ | |
_mainWindow.Hide(); | |
} | |
} | |
} | |
private void Application_Startup(object sender, StartupEventArgs e) | |
{ | |
_dispatcherTimer.Start(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment