Do you want to store the start time in the database when the user registers, and then verify the interval between the start time and the current time each time you open the application?
How about like this:
Window1(Register window):
<Grid>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="260,90,0,0" TextWrapping="Wrap" Text="Register Window" VerticalAlignment="Top" Height="40" Width="183" FontSize="22"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="52" Margin="215,172,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="289"/>
<Button x:Name="RegisterButton" Content="Register" HorizontalAlignment="Left" Margin="220,288,0,0" VerticalAlignment="Top" Width="95" Height="46" Click="RegisterButton_Click"/>
<Button x:Name="CancleButton" Content="Cancle" HorizontalAlignment="Left" Margin="356,288,0,0" VerticalAlignment="Top" Width="110" Height="47" Click="CancleButton_Click"/>
</Grid>
C# code:
public partial class Window1 : Window
{
public bool IsRegestered { get; set; }
public Window1()
{
InitializeComponent();
}
private void RegisterButton_Click(object sender, RoutedEventArgs e)
{
if (textBox.Text == "Pass")
{
IsRegestered = true;
this.Close();
}
else
{
MessageBox.Show("Wrong Register Key");
}
}
private void CancleButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
C# code in MainWindow:
public MainWindow()
{
InitializeComponent();
DateTime dateTime = new DateTime(2021, 7, 7, 10, 16, 00);
if (DateTime.Now - dateTime > TimeSpan.FromMinutes(3))
{
Window1 form2 = new Window1();
form2.ShowDialog();
if (!form2.IsRegestered)
{
this.Close();
}
}
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.