Starting a new thread and setting Me.Cursor.Current = Cursors.Wait

G

Guest

Hello,

I developed a winform application that executes a DTS package, the packages takes about 5 sec to execute so I am starting it on a worker thread. When a worker thread completes it raises an event, which is handled in the form.
While package is executing I want to set a cursor to hourglass. The event’s code is supposed to set back to default.
Unfortunately cursor icon doesn't change. I tried putting Me.Cursor.Current = Cursors.WaitCurs line before thread starts and after without any affect. What am I doing wrong?

Here's My code that starts a new thread:

Private Sub mnuExport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExport.Click

Dim DestinationFile As String
'get file name
SaveFileDialog1.Filter = "Excel files (*.xls)|*.xls|All files (*.*)|*.*"
If Not SaveFileDialog1.ShowDialog() = DialogResult.OK Then Exit Sub
DestinationFile = SaveFileDialog1.FileName
'***************


Dim sqlServer As String = System.Configuration.ConfigurationSettings.AppSettings.Get("SQLServer").ToString
Dim dtsExport As New DTSpackage
Dim thPackage As New Thread(AddressOf dtsExport.ExportData)
AddHandler dtsExport.ExportPackageExecuted, AddressOf ExportPackage_Executed
AddHandler dtsExport.ExportPackageFailed, AddressOf ExportPackage_Failed

'set Properties of DTS package
dtsExport.SQLServer = sqlServer
dtsExport.PackageName = "Data Export"
dtsExport.connModeFlag = DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection
dtsExport.Connection2 = "Connection2"
dtsExport.DestinationFile = DestinationFile

Me.Cursor.Current = Cursors.WaitCursor
thPackage.Start()
stBar.Text = "Exporting Data... Please Wait..."



End Sub

And Event:

Private Sub ExportPackage_Executed(ByVal Message As String, ByVal FileName As String)
stBar.Text = "Data Export completed"
Me.Cursor.Current = Cursors.Default

Dim p As New ProcessStartInfo
Try
If MsgBox("Data Export completed." & vbCrLf & "Open excel file.", MsgBoxStyle.OKCancel) = MsgBoxResult.OK Then
p.UseShellExecute = True
p.FileName = "excel"
p.Arguments = """" & FileName & """"
Process.Start(p)
End If
Catch ex As Exception

End Try

End Sub

Thank you in advance for your help
 
G

Guest

It turns out that usiong Me.Cursor= Cursors.WaitCursor instead of Me.Cursor.Current = Cursors.WaitCursor makes it work.

Anyone care to explain this?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top