Hello to all,
I hope that you could help me,

I create a windowsForm with just two buttons one is Start and other is Stop (to simulate the start and stop of my windows service).
The project is running fine, now i want to change to Windows Service, i think that is possibel i hope so .

How can i do it?

This is the code that i have in my windowsForm to start running the project.

Thanks for your time.

VB Code:
  1. Imports SifoxPM.MainConnection
  2. Imports System.Threading
  3.  
  4.  
  5. Public Class Form1
  6.     Inherits System.Windows.Forms.Form
  7.  
  8. #Region " Windows Form Designer generated code "
  9.  
  10.     Public Sub New()
  11.         MyBase.New()
  12.  
  13.         'This call is required by the Windows Form Designer.
  14.  
  15.         InitializeComponent()
  16.  
  17.         'Add any initialization after the InitializeComponent() call
  18.  
  19.     End Sub
  20.  
  21.     'Form overrides dispose to clean up the component list.
  22.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
  23.         If disposing Then
  24.             If Not (components Is Nothing) Then
  25.                 components.Dispose()
  26.             End If
  27.         End If
  28.         MyBase.Dispose(disposing)
  29.     End Sub
  30.  
  31.     'Required by the Windows Form Designer
  32.     Private components As System.ComponentModel.IContainer
  33.  
  34.     'NOTE: The following procedure is required by the Windows Form Designer
  35.     'It can be modified using the Windows Form Designer.  
  36.     'Do not modify it using the code editor.
  37.     Friend WithEvents btn_start As System.Windows.Forms.Button
  38.     Friend WithEvents btn_stop As System.Windows.Forms.Button
  39.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
  40.         Me.btn_start = New System.Windows.Forms.Button
  41.         Me.btn_stop = New System.Windows.Forms.Button
  42.         Me.SuspendLayout()
  43.         '
  44.         'btn_start
  45.         '
  46.         Me.btn_start.Location = New System.Drawing.Point(102, 54)
  47.         Me.btn_start.Name = "btn_start"
  48.         Me.btn_start.Size = New System.Drawing.Size(88, 32)
  49.         Me.btn_start.TabIndex = 0
  50.         Me.btn_start.Text = "Start"
  51.         '
  52.         'btn_stop
  53.         '
  54.         Me.btn_stop.Location = New System.Drawing.Point(102, 110)
  55.         Me.btn_stop.Name = "btn_stop"
  56.         Me.btn_stop.Size = New System.Drawing.Size(88, 32)
  57.         Me.btn_stop.TabIndex = 1
  58.         Me.btn_stop.Text = "Stop"
  59.         Me.btn_stop.Enabled = False
  60.         '
  61.         'Form1
  62.         '
  63.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
  64.         Me.ClientSize = New System.Drawing.Size(292, 271)
  65.         Me.Controls.Add(Me.btn_stop)
  66.         Me.Controls.Add(Me.btn_start)
  67.         Me.Name = "Form1"
  68.         Me.Text = "Form1"
  69.         Me.ResumeLayout(False)
  70.  
  71.     End Sub
  72.  
  73. #End Region
  74.     Dim csection As New CriticalSection(Nothing, Nothing, Nothing)
  75.     Private Sub btn_start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_start.Click
  76.  
  77.         Dim mainThread As New Thread(AddressOf csection.MainWorkingThread)
  78.         mainThread.Start()
  79.         btn_start.Enabled = False
  80.         btn_stop.Enabled = True
  81.  
  82.     End Sub
  83.  
  84.     Private Sub btn_stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_stop.Click
  85.         btn_stop.Enabled = False
  86.         csection.EndService()
  87.  
  88.     End Sub
  89.  
  90.  
  91.  
  92. End Class