473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Threading issue

Hi,
I have created a thread to execute my task but for some readon the
application still locks up until the task is completed.Here is my sample code
code on button

Private Sub cmd_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdImport.Click
Dim t As New Thread(AddressOf ExecuteTask)

t.Priority = ThreadPriority.Normal

t.Start()

End Sub

Ecexute task
Protected Sub ExecuteTask()
Dim sMessage As String
Dim lErr As Long, sSource As String, sDesc As String
oDts = New DTSPkg80.Package2Class
Try

oDts.LoadFromSQLServer("machine", "sa", "",
DTSPkg80.DTSSQLServerStorageFlags.DTSSQLStgFlag_De fault, , , , "NewPackage")

For Each oStep In oDts.Steps
oStep.ExecuteInMainThread = True
Next

oDts.Execute()

For Each oStep In oDts.Steps
If oStep.ExecutionResult =
DTSPkg80.DTSStepExecResult.DTSStepExecResult_Failu re Then
oStep.GetExecutionErrorInfo(lErr, sSource, sDesc)

sMessage = oStep.Name & " Failed"

Dim itmp As New Windows.Forms.ListViewItem(sMessage)

itmp.ImageIndex = 0

ListView1.Items.Add(itmp)

Else

sMessage = oStep.Name & " Succeeded"

End If
Next

oDts.UnInitialize()

Catch ex As Exception

MsgBox(ex.Message)

Finally

oStep = Nothing
oDts = Nothing
End Try

The program basically executes a package in sql server and displays the
messages (error or success) in a listview control. Wehn I run the program it
still locks up but runs perfect with the listview.

Any ideas?
Jul 21 '05 #1
1 1066
Chris <Ch***@discussions.microsoft.com> wrote:
I have created a thread to execute my task but for some readon the
application still locks up until the task is completed.Here is my sample code


For one thing, it looks like you're accessing the UI from within your
worker thread, which you mustn't do.

See http://www.pobox.com/~skeet/csharp/t...winforms.shtml

The main UI thread shouldn't be blocked by the code you've got though.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
4
by: JimD | last post by:
Is this safe? Any pitfalls? I have done threading in regular C# apps, but haven't had a needs to do threading in ASP.Net, until now. The issue I have ran into is this: Our corporate portal...
126
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.