Run timer in background in visual basic formUsing Git with Visual Studio.gitignore for Visual Studio Projects and SolutionsDifference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio?Can you force Visual Studio to always run as an Administrator in Windows 8?prgress bar when proccessing update application VB NETVisual Basic Async Task instead Sync TaskHow do I run CMD.exe as administratorChanging background color using combobox from a different form in Visual BasicConvert listbox to DataGridViewHow to inherit a form class to another form and is it even possible?

Does the Reduce option from the Enlarge/Reduce spell cause a critical hit to do 2d4 less damage?

Which meaning of "must" does the Slow spell use?

What stops you from using fixed income in developing countries?

How to say "I only speak one which is English." in French?

How to prevent a hosting company from accessing a VM's encryption keys?

Does trying to charm an uncharmable creature cost a spell slot?

Learning theory in a short period

What is Soda Fountain Etiquette?

Videos of surgery

Why are flat priors said to be proportional to a constant?

Why does the `ls` command sort files like this?

If I said I had $100 when asked, but I actually had $200, would I be lying by omission?

Availability Groups automatic failover is not so automatic

Is a Centaur PC considered an animal when calculating carrying capacity for vehicles?

Is the Amazon rainforest the "world's lungs"?

How many petaflops does it take to land on the moon? What does Artemis need with an Aitken?

The term Feed-forward and its meaning?

What is the name of this plot that has rows with two connected dots?

What to do about my 1-month-old boy peeing through diapers?

Will removing shelving screws from studs damage the studs?

Count the number of shortest paths to n

A probably wrong proof of the Riemann Hypothesis, but where is the mistake?

Is the internet in Madagascar faster than in UK?

Why does matter stay collapsed in the core, following a supernova explosion?



Run timer in background in visual basic form


Using Git with Visual Studio.gitignore for Visual Studio Projects and SolutionsDifference between Build Solution, Rebuild Solution, and Clean Solution in Visual Studio?Can you force Visual Studio to always run as an Administrator in Windows 8?prgress bar when proccessing update application VB NETVisual Basic Async Task instead Sync TaskHow do I run CMD.exe as administratorChanging background color using combobox from a different form in Visual BasicConvert listbox to DataGridViewHow to inherit a form class to another form and is it even possible?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















first I'm new in this, and I have this code that shows a prompt to restart or postpone the restart for a while, the issue is that i want to hide the message and bring it back after the time specified by the user.



I'm using a "visual basic form" and the time that restart will be postponed it's selected from a "ComboBox"



My code is as follows.



Imports System.Management
Imports System.Security.Permissions
Imports System
Imports System.IO
Imports System.Collections
Imports System.SerializableAttribute

Public Class Form2

Dim PostponeReboot As Integer = 50

Private Const CP_NOCLOSE_BUTTON As Integer = &H200
Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim myCp As CreateParams = MyBase.CreateParams
myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON
Return myCp
End Get
End Property

Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form1.Hide()
Label4.Text = SystemInformation.UserName
Button1.Enabled = False
ComboBox1.Enabled = False
Timer1.Interval = 1000
End Sub

Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

If CheckBox1.Checked Then
CheckBox2.Enabled = False
Button1.Enabled = True
ComboBox1.Enabled = False
ElseIf CheckBox1.Checked = 0 Then
CheckBox2.Enabled = True
Button1.Enabled = False
ComboBox1.Enabled = False
End If

End Sub

Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
If CheckBox2.Checked Then
CheckBox1.Enabled = False
ComboBox1.Enabled = True
Button1.Enabled = True
ElseIf CheckBox2.Checked = 0 Then
CheckBox1.Enabled = True
ComboBox1.Enabled = False
Button1.Enabled = False
End If
End Sub

Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.Text = "1 Hora" Then
PostponeReboot = 10
ElseIf ComboBox1.Text = "2 Horas" Then
PostponeReboot = 20
ElseIf ComboBox1.Text = "4 Horas" Then
PostponeReboot = 40
ElseIf ComboBox1.Text = "Seleccione" Then
Button1.Enabled = False
End If
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If CheckBox1.Checked Then
MessageBox.Show("Rebooting")
'Shell("shutdown -r -f -t 60")
Form1.Close()
End
ElseIf CheckBox2.Checked Then
MessageBox.Show(PostponeReboot)
Timer1.Start()
Me.Hide()
End If

If PostponeReboot = 0 Then
Me.Show()
Else
Me.Hide()
End If

End Sub


Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
PostponeReboot = PostponeReboot - 1
'Label5.Text = PostponeReboot
End Sub

End Class


In the first "If" sentence of below I want to start the timer and hide the form, and in the second "If" i want to bring it back the form, but the form remains hidden.



 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If CheckBox1.Checked Then
MessageBox.Show("Rebooting")
'Shell("shutdown -r -f -t 60")
Form1.Close()
End
ElseIf CheckBox2.Checked Then
MessageBox.Show(PostponeReboot)
Timer1.Start()
Me.Hide()
End If

If PostponeReboot = 0 Then
Me.Show()
Else
Me.Hide()
End If

End Sub


I've tried putting the second "If" sentence in another place but don't work, what I'm doing wrong.










share|improve this question






























    0















    first I'm new in this, and I have this code that shows a prompt to restart or postpone the restart for a while, the issue is that i want to hide the message and bring it back after the time specified by the user.



    I'm using a "visual basic form" and the time that restart will be postponed it's selected from a "ComboBox"



    My code is as follows.



    Imports System.Management
    Imports System.Security.Permissions
    Imports System
    Imports System.IO
    Imports System.Collections
    Imports System.SerializableAttribute

    Public Class Form2

    Dim PostponeReboot As Integer = 50

    Private Const CP_NOCLOSE_BUTTON As Integer = &H200
    Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
    Get
    Dim myCp As CreateParams = MyBase.CreateParams
    myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON
    Return myCp
    End Get
    End Property

    Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Form1.Hide()
    Label4.Text = SystemInformation.UserName
    Button1.Enabled = False
    ComboBox1.Enabled = False
    Timer1.Interval = 1000
    End Sub

    Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

    If CheckBox1.Checked Then
    CheckBox2.Enabled = False
    Button1.Enabled = True
    ComboBox1.Enabled = False
    ElseIf CheckBox1.Checked = 0 Then
    CheckBox2.Enabled = True
    Button1.Enabled = False
    ComboBox1.Enabled = False
    End If

    End Sub

    Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
    If CheckBox2.Checked Then
    CheckBox1.Enabled = False
    ComboBox1.Enabled = True
    Button1.Enabled = True
    ElseIf CheckBox2.Checked = 0 Then
    CheckBox1.Enabled = True
    ComboBox1.Enabled = False
    Button1.Enabled = False
    End If
    End Sub

    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
    If ComboBox1.Text = "1 Hora" Then
    PostponeReboot = 10
    ElseIf ComboBox1.Text = "2 Horas" Then
    PostponeReboot = 20
    ElseIf ComboBox1.Text = "4 Horas" Then
    PostponeReboot = 40
    ElseIf ComboBox1.Text = "Seleccione" Then
    Button1.Enabled = False
    End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If CheckBox1.Checked Then
    MessageBox.Show("Rebooting")
    'Shell("shutdown -r -f -t 60")
    Form1.Close()
    End
    ElseIf CheckBox2.Checked Then
    MessageBox.Show(PostponeReboot)
    Timer1.Start()
    Me.Hide()
    End If

    If PostponeReboot = 0 Then
    Me.Show()
    Else
    Me.Hide()
    End If

    End Sub


    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    PostponeReboot = PostponeReboot - 1
    'Label5.Text = PostponeReboot
    End Sub

    End Class


    In the first "If" sentence of below I want to start the timer and hide the form, and in the second "If" i want to bring it back the form, but the form remains hidden.



     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If CheckBox1.Checked Then
    MessageBox.Show("Rebooting")
    'Shell("shutdown -r -f -t 60")
    Form1.Close()
    End
    ElseIf CheckBox2.Checked Then
    MessageBox.Show(PostponeReboot)
    Timer1.Start()
    Me.Hide()
    End If

    If PostponeReboot = 0 Then
    Me.Show()
    Else
    Me.Hide()
    End If

    End Sub


    I've tried putting the second "If" sentence in another place but don't work, what I'm doing wrong.










    share|improve this question


























      0












      0








      0








      first I'm new in this, and I have this code that shows a prompt to restart or postpone the restart for a while, the issue is that i want to hide the message and bring it back after the time specified by the user.



      I'm using a "visual basic form" and the time that restart will be postponed it's selected from a "ComboBox"



      My code is as follows.



      Imports System.Management
      Imports System.Security.Permissions
      Imports System
      Imports System.IO
      Imports System.Collections
      Imports System.SerializableAttribute

      Public Class Form2

      Dim PostponeReboot As Integer = 50

      Private Const CP_NOCLOSE_BUTTON As Integer = &H200
      Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
      Get
      Dim myCp As CreateParams = MyBase.CreateParams
      myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON
      Return myCp
      End Get
      End Property

      Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      Form1.Hide()
      Label4.Text = SystemInformation.UserName
      Button1.Enabled = False
      ComboBox1.Enabled = False
      Timer1.Interval = 1000
      End Sub

      Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

      If CheckBox1.Checked Then
      CheckBox2.Enabled = False
      Button1.Enabled = True
      ComboBox1.Enabled = False
      ElseIf CheckBox1.Checked = 0 Then
      CheckBox2.Enabled = True
      Button1.Enabled = False
      ComboBox1.Enabled = False
      End If

      End Sub

      Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
      If CheckBox2.Checked Then
      CheckBox1.Enabled = False
      ComboBox1.Enabled = True
      Button1.Enabled = True
      ElseIf CheckBox2.Checked = 0 Then
      CheckBox1.Enabled = True
      ComboBox1.Enabled = False
      Button1.Enabled = False
      End If
      End Sub

      Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
      If ComboBox1.Text = "1 Hora" Then
      PostponeReboot = 10
      ElseIf ComboBox1.Text = "2 Horas" Then
      PostponeReboot = 20
      ElseIf ComboBox1.Text = "4 Horas" Then
      PostponeReboot = 40
      ElseIf ComboBox1.Text = "Seleccione" Then
      Button1.Enabled = False
      End If
      End Sub

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      If CheckBox1.Checked Then
      MessageBox.Show("Rebooting")
      'Shell("shutdown -r -f -t 60")
      Form1.Close()
      End
      ElseIf CheckBox2.Checked Then
      MessageBox.Show(PostponeReboot)
      Timer1.Start()
      Me.Hide()
      End If

      If PostponeReboot = 0 Then
      Me.Show()
      Else
      Me.Hide()
      End If

      End Sub


      Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
      PostponeReboot = PostponeReboot - 1
      'Label5.Text = PostponeReboot
      End Sub

      End Class


      In the first "If" sentence of below I want to start the timer and hide the form, and in the second "If" i want to bring it back the form, but the form remains hidden.



       Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      If CheckBox1.Checked Then
      MessageBox.Show("Rebooting")
      'Shell("shutdown -r -f -t 60")
      Form1.Close()
      End
      ElseIf CheckBox2.Checked Then
      MessageBox.Show(PostponeReboot)
      Timer1.Start()
      Me.Hide()
      End If

      If PostponeReboot = 0 Then
      Me.Show()
      Else
      Me.Hide()
      End If

      End Sub


      I've tried putting the second "If" sentence in another place but don't work, what I'm doing wrong.










      share|improve this question














      first I'm new in this, and I have this code that shows a prompt to restart or postpone the restart for a while, the issue is that i want to hide the message and bring it back after the time specified by the user.



      I'm using a "visual basic form" and the time that restart will be postponed it's selected from a "ComboBox"



      My code is as follows.



      Imports System.Management
      Imports System.Security.Permissions
      Imports System
      Imports System.IO
      Imports System.Collections
      Imports System.SerializableAttribute

      Public Class Form2

      Dim PostponeReboot As Integer = 50

      Private Const CP_NOCLOSE_BUTTON As Integer = &H200
      Protected Overloads Overrides ReadOnly Property CreateParams() As CreateParams
      Get
      Dim myCp As CreateParams = MyBase.CreateParams
      myCp.ClassStyle = myCp.ClassStyle Or CP_NOCLOSE_BUTTON
      Return myCp
      End Get
      End Property

      Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
      Form1.Hide()
      Label4.Text = SystemInformation.UserName
      Button1.Enabled = False
      ComboBox1.Enabled = False
      Timer1.Interval = 1000
      End Sub

      Private Sub CheckBox1_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox1.CheckedChanged

      If CheckBox1.Checked Then
      CheckBox2.Enabled = False
      Button1.Enabled = True
      ComboBox1.Enabled = False
      ElseIf CheckBox1.Checked = 0 Then
      CheckBox2.Enabled = True
      Button1.Enabled = False
      ComboBox1.Enabled = False
      End If

      End Sub

      Private Sub CheckBox2_CheckedChanged(sender As Object, e As EventArgs) Handles CheckBox2.CheckedChanged
      If CheckBox2.Checked Then
      CheckBox1.Enabled = False
      ComboBox1.Enabled = True
      Button1.Enabled = True
      ElseIf CheckBox2.Checked = 0 Then
      CheckBox1.Enabled = True
      ComboBox1.Enabled = False
      Button1.Enabled = False
      End If
      End Sub

      Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, e As EventArgs) Handles ComboBox1.SelectedIndexChanged
      If ComboBox1.Text = "1 Hora" Then
      PostponeReboot = 10
      ElseIf ComboBox1.Text = "2 Horas" Then
      PostponeReboot = 20
      ElseIf ComboBox1.Text = "4 Horas" Then
      PostponeReboot = 40
      ElseIf ComboBox1.Text = "Seleccione" Then
      Button1.Enabled = False
      End If
      End Sub

      Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      If CheckBox1.Checked Then
      MessageBox.Show("Rebooting")
      'Shell("shutdown -r -f -t 60")
      Form1.Close()
      End
      ElseIf CheckBox2.Checked Then
      MessageBox.Show(PostponeReboot)
      Timer1.Start()
      Me.Hide()
      End If

      If PostponeReboot = 0 Then
      Me.Show()
      Else
      Me.Hide()
      End If

      End Sub


      Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
      PostponeReboot = PostponeReboot - 1
      'Label5.Text = PostponeReboot
      End Sub

      End Class


      In the first "If" sentence of below I want to start the timer and hide the form, and in the second "If" i want to bring it back the form, but the form remains hidden.



       Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      If CheckBox1.Checked Then
      MessageBox.Show("Rebooting")
      'Shell("shutdown -r -f -t 60")
      Form1.Close()
      End
      ElseIf CheckBox2.Checked Then
      MessageBox.Show(PostponeReboot)
      Timer1.Start()
      Me.Hide()
      End If

      If PostponeReboot = 0 Then
      Me.Show()
      Else
      Me.Hide()
      End If

      End Sub


      I've tried putting the second "If" sentence in another place but don't work, what I'm doing wrong.







      vb.net visual-studio visual-studio-2017






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 20:25









      Mauricio Torres OlveraMauricio Torres Olvera

      32 bronze badges




      32 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          2















          I assume here that your Timer1 class raises the Timer1.Tick event every x time after Timer1.Start() is called. The fact that the form can hide tells me Timer1.Start() isn't a blocking method. As such, your second if statement will be verified right after you hide the form, without waiting for the PostponeReboot variable to reach zero. This particular button handler would then exit and your form would remain hidden. What I see is that you already have an event handler for each tick of your timer. Why not use this handler to verify the state of your PostponeReboot variable?



          Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
          PostponeReboot = PostponeReboot - 1

          If PostponeReboot = 0 Then
          Timer1.Stop() 'I would assume
          Me.Show()
          End If
          End Sub


          Although, I would recommend you to try other solutions, like having your timer raise an event only when it reaches the elapsed time (so you don't have to handle each ticks unnecessarily). I would also recommend looking into an Universal Windows App with Toast Notifications as you could set a Notification to appear at a set time (handled by Windows) so that you don't have to have a thread running in the background for this.






          share|improve this answer



























          • It's true, so basic and i forgot to put in the PostponeReboot variable reaches the "0" and continues with -1, -2, -3 and so.

            – Mauricio Torres Olvera
            Mar 27 at 21:28










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385865%2frun-timer-in-background-in-visual-basic-form%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2















          I assume here that your Timer1 class raises the Timer1.Tick event every x time after Timer1.Start() is called. The fact that the form can hide tells me Timer1.Start() isn't a blocking method. As such, your second if statement will be verified right after you hide the form, without waiting for the PostponeReboot variable to reach zero. This particular button handler would then exit and your form would remain hidden. What I see is that you already have an event handler for each tick of your timer. Why not use this handler to verify the state of your PostponeReboot variable?



          Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
          PostponeReboot = PostponeReboot - 1

          If PostponeReboot = 0 Then
          Timer1.Stop() 'I would assume
          Me.Show()
          End If
          End Sub


          Although, I would recommend you to try other solutions, like having your timer raise an event only when it reaches the elapsed time (so you don't have to handle each ticks unnecessarily). I would also recommend looking into an Universal Windows App with Toast Notifications as you could set a Notification to appear at a set time (handled by Windows) so that you don't have to have a thread running in the background for this.






          share|improve this answer



























          • It's true, so basic and i forgot to put in the PostponeReboot variable reaches the "0" and continues with -1, -2, -3 and so.

            – Mauricio Torres Olvera
            Mar 27 at 21:28















          2















          I assume here that your Timer1 class raises the Timer1.Tick event every x time after Timer1.Start() is called. The fact that the form can hide tells me Timer1.Start() isn't a blocking method. As such, your second if statement will be verified right after you hide the form, without waiting for the PostponeReboot variable to reach zero. This particular button handler would then exit and your form would remain hidden. What I see is that you already have an event handler for each tick of your timer. Why not use this handler to verify the state of your PostponeReboot variable?



          Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
          PostponeReboot = PostponeReboot - 1

          If PostponeReboot = 0 Then
          Timer1.Stop() 'I would assume
          Me.Show()
          End If
          End Sub


          Although, I would recommend you to try other solutions, like having your timer raise an event only when it reaches the elapsed time (so you don't have to handle each ticks unnecessarily). I would also recommend looking into an Universal Windows App with Toast Notifications as you could set a Notification to appear at a set time (handled by Windows) so that you don't have to have a thread running in the background for this.






          share|improve this answer



























          • It's true, so basic and i forgot to put in the PostponeReboot variable reaches the "0" and continues with -1, -2, -3 and so.

            – Mauricio Torres Olvera
            Mar 27 at 21:28













          2














          2










          2









          I assume here that your Timer1 class raises the Timer1.Tick event every x time after Timer1.Start() is called. The fact that the form can hide tells me Timer1.Start() isn't a blocking method. As such, your second if statement will be verified right after you hide the form, without waiting for the PostponeReboot variable to reach zero. This particular button handler would then exit and your form would remain hidden. What I see is that you already have an event handler for each tick of your timer. Why not use this handler to verify the state of your PostponeReboot variable?



          Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
          PostponeReboot = PostponeReboot - 1

          If PostponeReboot = 0 Then
          Timer1.Stop() 'I would assume
          Me.Show()
          End If
          End Sub


          Although, I would recommend you to try other solutions, like having your timer raise an event only when it reaches the elapsed time (so you don't have to handle each ticks unnecessarily). I would also recommend looking into an Universal Windows App with Toast Notifications as you could set a Notification to appear at a set time (handled by Windows) so that you don't have to have a thread running in the background for this.






          share|improve this answer















          I assume here that your Timer1 class raises the Timer1.Tick event every x time after Timer1.Start() is called. The fact that the form can hide tells me Timer1.Start() isn't a blocking method. As such, your second if statement will be verified right after you hide the form, without waiting for the PostponeReboot variable to reach zero. This particular button handler would then exit and your form would remain hidden. What I see is that you already have an event handler for each tick of your timer. Why not use this handler to verify the state of your PostponeReboot variable?



          Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
          PostponeReboot = PostponeReboot - 1

          If PostponeReboot = 0 Then
          Timer1.Stop() 'I would assume
          Me.Show()
          End If
          End Sub


          Although, I would recommend you to try other solutions, like having your timer raise an event only when it reaches the elapsed time (so you don't have to handle each ticks unnecessarily). I would also recommend looking into an Universal Windows App with Toast Notifications as you could set a Notification to appear at a set time (handled by Windows) so that you don't have to have a thread running in the background for this.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 27 at 21:45

























          answered Mar 27 at 21:02









          Olivier SamsonOlivier Samson

          5112 silver badges11 bronze badges




          5112 silver badges11 bronze badges















          • It's true, so basic and i forgot to put in the PostponeReboot variable reaches the "0" and continues with -1, -2, -3 and so.

            – Mauricio Torres Olvera
            Mar 27 at 21:28

















          • It's true, so basic and i forgot to put in the PostponeReboot variable reaches the "0" and continues with -1, -2, -3 and so.

            – Mauricio Torres Olvera
            Mar 27 at 21:28
















          It's true, so basic and i forgot to put in the PostponeReboot variable reaches the "0" and continues with -1, -2, -3 and so.

          – Mauricio Torres Olvera
          Mar 27 at 21:28





          It's true, so basic and i forgot to put in the PostponeReboot variable reaches the "0" and continues with -1, -2, -3 and so.

          – Mauricio Torres Olvera
          Mar 27 at 21:28








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55385865%2frun-timer-in-background-in-visual-basic-form%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

          Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript