Skip to content

Instantly share code, notes, and snippets.

@martinnormark
Created July 6, 2021 09:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martinnormark/b5c00b95b160670575825a29a457bbc3 to your computer and use it in GitHub Desktop.
Save martinnormark/b5c00b95b160670575825a29a457bbc3 to your computer and use it in GitHub Desktop.
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