473,320 Members | 2,048 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,320 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 1063
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: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.