Home » VB.Net

Start / Pause button to start and/or pause a program

I am trying to make a start and pause button (and hence continue) to start, pause, and continue my program.  The start button works but the pause button does not.  Can someone look at my code and see what the pause button needs to do to pause the program?  I am using VB 2005.  Here is my code.  Thanks

Imports Microsoft.Win32
Imports System.Threading
PublicClass Form1
  Dim m_event As ManualResetEvent = New ManualResetEvent(False)
  Dim tw As Thread
  PrivateSub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
  EndSubPrivateSub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
    'when timer ends Itunes runs and plays a song
    Process.Start("Itunes.exe", "c:\Pieces_of_April.mp3")
    Timer1.Enabled = FalseMe.Visible = FalseEndEndSubPrivateSub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
    If RadioButton2.Checked = TrueThen
      Timer1.Enabled = True
      Timer1.Interval = 1200000  'clock runs for 20 minutesEndIfEndSubPrivateSub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
    If RadioButton3.Checked = TrueThen
      Timer1.Enabled = True
      Timer1.Interval = 1800000  'clock runs for 30 minutesEndIfEndSubPrivateSub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
    If RadioButton4.Checked = TrueThen
      Timer1.Enabled = True
      Timer1.Interval = 2700000  'clock runs for 45 minutesEndIfEndSubPrivateSub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
    If RadioButton5.Checked = TrueThen
      Timer1.Enabled = True
      Timer1.Interval = 3600000  'clock runs for 60 minutesEndIfEndSubPrivateSub Form1_FormClosing(ByVal sender AsObject, ByVal e As System.Windows.Forms.FormClosingEventArgs) HandlesMyBase.FormClosing
  EndSubPrivateSub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load
    Start.Text = "Start"
    Pause.Text = "Pause"
    Pause.Enabled = False
    tw = New Thread(AddressOf run)
  EndSubPrivateSub Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Start.Click
    Start.Enabled = False
    Pause.Enabled = TrueIf RadioButton1.Checked = TrueThen
      Timer1.Enabled = True
      Timer1.Interval = 15000  'clock runs for 15 secondsEndIfEndSubPrivateSub Pause_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Pause.Click
    Pause.Enabled = False
    Start.Enabled = TrueEndSubPublicSub run()
    Dim CounterCreationData AsInteger = 0
      Console.WriteLine("executing" & DateTime.Now.ToLongTimeString)


David H.


3 Answers Found


Answer 1

Put this code in the Pause Click:

Timer1.Enabled = False

Answer 2

I did that but it doesn't do what I really want it too and that is to pause... but pick up where it

left off when the start button is pressed again.  The Timer1.Enabled = False will stop the

program but when I press start again the timer goes back to the beginning of the time that was



Answer 3

OK I see your issue. Setting timer to 15000 means it ticks every 15 secs, so you do not have any control over it in between this time (I mean you do not know how much time has elapsed etc) So what I suggest is to do this:


Timer1.Interval = 1000

Dim timeCounter As Int16

PrivateSub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  If timeCounter == 15 Then
    'when timer ends Itunes runs and plays a song
    Process.Start("Itunes.exe", "c:\Pieces_of_April.mp3")
    Timer1.Enabled = FalseMe.Visible = False
  End If

What we are doing here is that Timer1 will tick every sec so you can pause it using 
Timer1.Enabled = False in Pause Click
Also when you start again, timeCounter is somewhere between 0 to 15 and would get back to incrementing towards 15 and when it reaches 15 (in 15 secs) the song is played.



I am using Silverlight 4, C# and .NET 4.0 with Expression Blend 4. and I am a designer, so sometime the simple things seem very complicated.

I have created a storyboard and...

1. Want it to begin automatically after  the animation is loaded

2. Pause on frame 10

3. Resume play when the "Next" button is clicked

4. Pause on frame 20

5. Resume play when the "Next" button is clicked

6. Cycle through that routine "n" number of times

7. On the final Pause when the user clicks "Next" or another button like "Play again" the Storyboard will start over back at frame one.

Now this sounds very simple, but I use Blend 4.0 and there does not seem to be UI controls to accomplish this seemingly simple routine. Thanks in advance. I appreciate all the help you can give me.


I have a USB device that comes with software to that allows you to output data through the device using horizontal scroll bars.  I am trying to modify this program so that the data is read from a file (.mdb) and then pauses for a brief amount of seconds (based on the line of data read) until reading the next line of data.  The program I have seems to work fine as long as I don't have the USB device connected.  Once I connect the device, the program reads the first line of data and then just 'hangs'.  I have put the application.doevents() everywhere I can think of but it does no good.

The sample program using horizontal scroll bars that comes with the device uses a timer1 with an interval value of 1.  Best I can tell this sends program information to the device every millisecond.  I have been unable to figure out how to incorporate a new timer2 which changes the interval based on the data read.

Any help would be appreciated.


Hi all,


I am trying to make a program in VB. NET CF in VS 2008 and I've run into a bit of a problem.  I'm a bit of a noob when it comes to writing programs in VB, let alone .NET CF, so please bear with me.


My problem is that I have a textbox that is filled with a line of data from an attached barcode scanner.  I want to make it so when something is scanned into this box, another function is triggered (it clears the textbox and commits the data to a CSV file, so the user can scan another barcode).  I was using a .TextChanged function so that when the text was changed in this textbox, it would commit it then, however the problem with this approach is that if the serial number is 77G8DS, then it will commit 7,7,G,8,D and S individually, instead of an entire string.

My attempted workaround was to pause the script for 750ms, and then check if the textbox had changed then, but this didn't work either.  I tried to use thread.sleep(750) for that.

Any ideas? Sorry if I dont make a lot of sense, been coding for most the day and my brains gone to mush :)

I have a routine that prints multiple rectangles and I need to put a delay in between the printing of each object.
Dim i AsIntegerFor i = 0 To 49
      Canvas.SetTop(lstRectangles(i), 150 + (i))
      Canvas.SetLeft(lstRectangles(i), 150 + (i))
      lstRectangles(i).Fill = Brushes.Yellow
      'Dim x As Integer'For x = 1 To 10000000' do nothing'Next'System.Threading.Thread.Sleep(100)Next i

As you can see I have tried a couple of basic things which only provide a delay to the displaying of all objects at once; i.e. not between each object. I have created a DispatcherTimer instance but can't see how this can be used to work here.

Can anyone help please?

I have a routine that prints multiple rectangles and I need to put a delay in between the printing of each object.
Dim i AsIntegerFor i = 0 To 49
   Canvas.SetTop(lstRectangles(i), 150 + (i))
   Canvas.SetLeft(lstRectangles(i), 150 + (i))
   lstRectangles(i).Fill = Brushes.Yellow
   'Dim x As Integer'For x = 1 To 10000000' do nothing'Next'System.Threading.Thread.Sleep(100)Next i

As you can see I have tried a couple of basic things which only provide a delay to the displaying of all objects at once; i.e. not between each object. I have created a DispatcherTimer instance but can't see how this can be used to work here.

Can anyone help please?


I have searched different forums/websites and haven't found my exact answer.  I would like for my program to pause for about 3-5 seconds and then close/exit after pausing.  I've used the my.application.doevents() and threading.thead.sleep as well, which may work, but when I add close() after the pause it just closes.  Any help is appreciated!





I´m a newb in excel macros.

I have a sheet where the users must define how many reports wants to pull by choosing from a drop down list (of table, column, row and data from a pivot table) .

I manage to create a generic pivot table that respondes to the vary inputs but I cant make the macro to stop until a button is clicked (button "Next data")

The button should stop the macro until is clicked, then it will read the cells in a for...next loop and store the data in an array for the report being created lately. 

I dont know how to create that stop button.

Here is the code so far


numero = Sheets("Principal").Cells(3, 8)

For n = 1 To number


"STOP BUTTON" (Next Data)


pivot1(n) = Sheets("Principal").Cells(6, 7)   

y1(n) = Sheets("Principal").Cells(8, 7)    

x1(n) = Sheets("Principal").Cells(10, 7)    

v1(n) = Sheets("Principal").Cells(12, 7)  


(clear cells)

next n

after read the data, it clears the cells and do next n value until reaches the number of pivot tables the user wants to create.


Could you please show me the right way to do so?


Kind Regards



does anyone know why i do NOT have a -pause- button in my C#2010 IDE?

is this common?  was there a memo?  where'd my pause button go?


I am a total beginner so go easy and please give any code examples you can lend :)

I am trying to build a simple app that will start another program.

The command line that works in a dos batch file is c:\program files\pixell\Wall Control\wallctl.exe -layout=c:\1.lay 

with my code below this works,  c:\program files\pixell\Wall Control\wallctl.exe  but the switch info above doesnt get passed, I get a run time error.


Public Class Form1

    Dim layout1 As String

    Dim layout2 As String

PublicClass Form1
  Dim layout1 AsStringDim layout2 AsStringPrivateSub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
    layout1 = TextBox1.Text
  EndSubPrivateSub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click




My question comes from a particular task that I want performed when a program is started. It comes out of the need to stop an add-on once Internet Explorer is started. I don't want to disable the add-on, and in fact it will restart itself when it discovers that it is turned off via the process manager in Windows Task Manager.

Fact is, the program is the "GoogleToolbarUser_32.exe" and is needed to utilize Google's Toolbar. But, the problem lies in that the program hangs and uses one full CPU when IE is first started up. End the process and it restarts without the CPU hungry bug that takes up so much resources.

I know I can wait until Google fixes this problem but I would like to deal with it myself until then. Using Task Scheduler seemed the most logical method to accomplish this task. But I can't seem to find the procedure that would be used to do this, if any. Seems like this would be a common request. Not so much to shut down a problematic program but in other regards. Say to detect when a program starts, to say, start a log or something of the sort.

Thank you in advance and I hope this is easily accomplished.  Jerry



Im making a project for a PDA with Windows Mobile 5.0 Pocket PC and i create a cab-file for the installation accordingly to the specifications.
I want to start a process that will syncronize databases within the cab-installationprocess.
I have found (it seems) good tutorials.

the only difference with this tutorial i see is the "Win32 Smart Device DLL"-project i have a "Win32 Smart Device Project" and a "MFC Smart Device DLL" but thats not exactly the name, i assume that they ment the "Win32 Smart Device Project" but i have tryed both just in case.

I have built an test application that just should create a file accordingly to the msdn-tutorial also tryed to start a process accordingly to

My problem is that when i install the cab-file on the PDA nothing else but the installation happends, no file created or no program started.

Please help me in solving this issue, so if anyone have any ideas?

the setuprun.cpp in Source Files in the win32 Smart Device Project

A warning when i build this project:
LIBCMTD.lib(gshandler.obj) : warning LNK4099: PDB 'libbmtd.pdb' was not found with 'C:\Program\Microsoft Visual Studio 8
\VC\ce\lib\ARMV4I\LIBCMTD.lib' or at 'c:\TestProjs\DeviceApplication2\setuprun\Windows Mobile 5.0 Pocket PC SDK (ARMV4I)
\Debug\libbmtd.pdb'; linking object as if no debug info

Code Snippet
#include "stdafx.h"
#include <windows.h>
#include <commctrl.h>
#include "ce_setup.h"

HINSTANCE g_hinstModule;
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved)
   switch (ul_reason_for_call)
        case DLL_PROCESS_ATTACH:
        case DLL_THREAD_ATTACH:
        case DLL_THREAD_DETACH:
        case DLL_PROCESS_DETACH:
            g_hinstModule = (HINSTANCE)hModule;
    return TRUE;

codeINSTALL_EXIT Install_Exit(
    HWND    hwndParent,
    LPCTSTR pszInstallDir,
    WORD    cFailedDirs,
    WORD    cFailedFiles,
    WORD    cFailedRegKeys,
    WORD    cFailedRegVals,
    WORD    cFailedShortcuts
    PROCESS_INFORMATION pi      = {0};
    codeINSTALL_EXIT    cie     = codeINSTALL_EXIT_DONE;


_tcscpy(szPath, pszInstallDir);

_tcscat(szPath, _T("\\"));

, _T("DeviceApplication2.exe"));

MessageBox(GetForegroundWindow(), szPath, L"status", MB_OK);

if (!CreateProcess(szPath, NULL, NULL, NULL, NULL, 0, NULL, NULL, NULL, &pi))
  MessageBox(GetForegroundWindow(), szPath, L"failed", MB_OK);
return cie;

the inf-file that VS creates from the Smart Device CAB Project

Code Snippet
Signature="$Windows NT$"
CESignature="$Windows CE$"





2=,"Common2",,"c:\testprojs\deviceapplication2\setuprun\windows mobile 5.0 pocket pc sdk (armv4i)\debug\"


Shortcuts=0,%CE2%\Start Menu





Running Visual Studio 2008 on Windows 7 Pro, x64

A strange error that started popping up a while ago, after compiling my program and starting my program, VS 2008 pops up a dialog saying that it failed with a dialog

"The operation could not be completed. The process cannot access the file because it is being used by another process".

Trying to run it again a new dialog pops up and says:

Visual Studio could not copy a support file to this location : 'H:\usr\src\MyProg\MyProg\bin\Debug\MyProg.vshost.exe'. Please verify the path exists and is writable"

If I restart, and try to run it a second time, the 2nd dialog pops up. Now on the THIRD start, the debug version runs just fine !

Any idea what to look for here ?

I've got a very simple SQL database program that lets me change user information in a table.  I have two textboxes that show the user information but I want it to show a specific record as the program loads.  How can I do this instead of having it just load record one?

I have a web application project which hosts a workflow. I have a runner application which will allow me to start new instances and control existing instances. When the dev user hits Start or Start without debugging I want the runner application to launch. No problems so far, set the start action and off I go.

My runner application calls the AppFabric powershell scripts under the hood inside a runspace. This seems to work fine until I am running from inside a web application project with the debugger attached on launching the runner (by setting the start action). The powershell scripts take ages in this scenario for some reason.

I don't really want the user to debug my runner app but only the web app. How do I get visual studio not to attach to the runner when launched but still attach to the web app (IIS)?






I want to write a application which uses Powerpoint Interop to extract some information from Powerpoint files.

I want to make sure that application starts as soon as windows is started (don't want to wait till user logins). I want to know what is the best way to solve this problem.

I tried using a service, but when I try to access Powerpoint interop using a window service I get an error saying cannot access file. (Service don't have the privileges for accessing interop). I even tried running service with admin user account and adding manifest but no sucess there.

I tried Run entry in the registry (even under HKLM), but as it looks like it is the list of the program that needs to start when a user login.

I want to know how can I start my programe when machine starts (before user  login). I am sure there might be some windows program which might run in this mode, can I make such arrangements for my application.


Installed IE 8 final the other day and since when i debug in VS 2008 with an asp.net project I get an error, sometimes:

Unable to start program http://localhost:50183/directory/asppage.aspx element not found.

Now, it does open IE 8 , but IE 8 says connecting I cannot close it except by the task manager. This does not happen all the time. This is driving me nuts and I cannot find any information on this issue anywhere.

Any information on how to address this issue would be great.


im working on a project in visual studio 2008 that used to compilebut now once i hit the compile does its usual thing then suddenly i get the error message


Unable to start program (file location) 

the system cannot find the file specified


i have tryed to un install and re install visual but no success

 i looed for the file location and i it doesnt exist


please help!



I want to Unpin all the pinend items from Start menu using registry, in Win 7 -64 bit OS. Please sugegct me, how can I do this.






I am trying to run a new process 9EXE) from a VB.NET program. Basically I am doing something similar to this:

Dim proc AsNew Process
    Dim pi AsNew ProcessStartInfo

    pi.FileName = CMD
    pi.Arguments = ARG
    pi.UseShellExecute = False
    pi.RedirectStandardError = True
    pi.RedirectStandardOutput = True
    pi.CreateNoWindow = True

    proc.StartInfo = pi

      Dim std_out_ AsString = ""Dim std_err_ AsString = ""Dim std_out As StreamReader = proc.StandardOutput()
      Dim std_err As StreamReader = proc.StandardError()
      std_out_ = std_out.ReadToEnd()
      std_err_ = std_out.ReadToEnd()

      RunProc = std_out_ & vbNewLine & std_err_ & vbNewLine
    Catch ex As Exception
      Return ex.Message

The above method is launching the EXE fine on Windows XP fine, but it is not launching in Windows 2003 SP2. Is there anything special to be done on Windows 2003 SP2? I am running the processes and launching the new exe under the same USER CONTEXT and there is no need for me to switch users. Any help is appreciated.




I'm working on an update to one of my programs, and for some reason this new version isn't working on Windows XP.  It crashes immediately upon launching (before the GUI is even visible on screen).  This shows up in the Event Viewer:

EventType clr20r3, P1 myprogram.exe, P2, P3 4c660197, P4 presentationframework, P5, P6 4938d608, P7 625a, P8 e1, P9 system.windows.markup.xamlparse, P10 NIL.
I have no problems on Windows Vista or Windows 7.  I don't have Visual Studio installed on my XP machine ... how do I pinpoint this problem??


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure