osamaakhattab
New member
- Joined
- Feb 8, 2006
- Messages
- 4
- Programming Experience
- 1-3
Dear All:
I have major problem which could be summarised as follow:
I have main form which has Progressbar and i attached Contextmenue Strip to that form which Start and Stop the Progressbar . when i click start it must start increment the progress bar and when i click stop it will stop it. when i click start i cant press righ click mouse the form will freez i tried to do thread but even though it dosnt work :
This is the code and i hope any one can help
I have major problem which could be summarised as follow:
I have main form which has Progressbar and i attached Contextmenue Strip to that form which Start and Stop the Progressbar . when i click start it must start increment the progress bar and when i click stop it will stop it. when i click start i cant press righ click mouse the form will freez i tried to do thread but even though it dosnt work :
This is the code and i hope any one can help
VB.NET:
Private Sub StartDepreciation_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles StartDepreciation.Click
Try
Dim TestMe As New DepreciateNow(Me)
Dim s As New Thread(AddressOf TestMe.StartStockDepreciation)
s.SetApartmentState(ApartmentState.STA)
s.IsBackground = True
's.IsBackground = True
'Thread.VolatileRead(Me)
s.Start()
' SetProgressBar()
' StartStockDepreciation()
Catch ex As Exception
End Try
End Sub
Public Class DepreciateNow
Public Sub New(ByVal f As Form)
formMine = CType(f, frmStockDepreciationConfig)
End Sub
Public Sub New()
End Sub
Public Delegate Sub TestDel()
Public Sub StartStockDepreciation()
Dim Delegated As New TestDel(AddressOf StartStockDepreciation)
'if in
If CType(formMine, frmStockDepreciationConfig).InvokeRequired Then
CType(formMine, frmStockDepreciationConfig).Invoke(Delegated)
Else
Dim blDepreciating As Boolean = False
Dim s As New frmStockDepreciationConfig
Dim dsStock As New DataSet
Dim intStockID, intNumRows, intRow As Int32
Try
'Check there are stock items in the stock table
aNames.Clear()
aValues.Clear()
dsStock = clsHolisTech.Execute("usp_STC_List_Stock_Global", aNames, aValues)
If dsStock.Tables(0).Rows.Count < 1 Then
MessageBox.Show("There are no Stock Items to Depreciate.", _
"Aborting Depreciation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
dsStock.Dispose()
Exit Sub
End If
intNumRows = dsStock.Tables(0).Rows.Count
intRow = 0
blDepreciating = True
CType(formMine, frmStockDepreciationConfig).cmsMain.Items("StartDepreciation").Enabled = False
'frmStockDepreciationConfig.cmsMain.Items("StartDepreciation").Enabled = False
CType(formMine, frmStockDepreciationConfig).cmsMain.Items("StopDepreciation").Enabled = True
While intRow < intNumRows And blDepreciating = True
intStockID = CType(dsStock.Tables(0).Rows(intRow).Item("StockID"), Int32)
Try
'Call Depreciate function from StockSharedFunctions class to depreciate a single stock item
StockSharedFunctions.DepreciateStock(intStockID)
Catch
MessageBox.Show("There was an unexpected problem Depreciating Stock ID " _
& intStockID.ToString & ". Please record this number and contact your System Adminstrator for assistance.", _
"Depreciation Error", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
'
''Start Thread Which will initialise the Progress Bar
'
'Dim ConnectionThread As New Thread(AddressOf test)
'ConnectionThread.SetApartmentState(ApartmentState.STA)
'ConnectionThread.Start()
'ConnectionThread.IsBackground = True
CType(formMine, frmStockDepreciationConfig).UserControl11.ProgressBar1.Increment(1)
intRow = intRow + 1
' ConnectionThread.Suspend()
'pbarProgress.Value = intRow
'pbarProgress.Refresh()
End While
Catch ex As Exception
End Try
End If
End Sub
end class
Last edited by a moderator: