VB.net and threading

H

hngo01

All,
I am developing a vb.net using threading....
I have a button to print a doc (it takes about 5-10 seconds to finish that
process). As soon I click that button I start a thread and then I go to a
different tab to do other stuff....But while printing it prevents me from
doing other stuff (UI looks like freeze)...make me wait before printing is
finished. I thought the thread will solve this problem for me but it
doesn’t....Please advice. Thanks
 
T

Tom Shelton

All,
I am developing a vb.net using threading....
I have a button to print a doc (it takes about 5-10 seconds to finish that
process). As soon I click that button I start a thread and then I go to a
different tab to do other stuff....But while printing it prevents me from
doing other stuff (UI looks like freeze)...make me wait before printing is
finished. I thought the thread will solve this problem for me but it
doesn?t....Please advice. Thanks

Code sample please... It's very hard to diagnose these kinds of issues
without seeing what it is your doing. So, post the smallest possible
code sample that demonstrates the issue:

For what is meant by short and complete sample have a look here:
http://www.yoda.arachsys.com/csharp/complete.html

That is very good advice.

Now, I'm going to give some more advice - without looking at the code :)
If you are using VB2005 or greater, don't use an explicit thread for
this. Take a look at the BackgroundWorker component.
 
K

kimiraikkonen

Code sample please...  It's very hard to diagnose these kinds of issues
without seeing what it is your doing.  So, post the smallest possible
code sample that demonstrates the issue:

For what is meant by short and complete sample have a look here:http://www..yoda.arachsys.com/csharp/complete.html

That is very good advice.

Now, I'm going to give some more advice - without looking at the code :)
If you are using VB2005 or greater, don't use an explicit thread for
this.  Take a look at the BackgroundWorker component.

Hi dear Tom,
I was seeking a similar help about multi-threading then came accross
Background Worker. My question is: Does background worker do
everything that a separated thread can do? In some of my apps, if i
run external processes or functions, UI (form) seems frozen and screen
is distorted. However in rare cases, background worker helps, but
although i use Background Worker, i sometimes get an multi-threading
error like "cross thread operation is not valid" although my code is
in background workers_doWork event.

What can cause this?

Thanks :)
 
T

Tom Shelton

Hi dear Tom,
I was seeking a similar help about multi-threading then came accross
Background Worker. My question is: Does background worker do
everything that a separated thread can do? In some of my apps, if i

Pretty much - and more. The BackgroundWorker will spawn a new thread of
execution, and if used properly will sync the callbacks for you :)
run external processes or functions, UI (form) seems frozen and screen
is distorted. However in rare cases, background worker helps, but
although i use Background Worker, i sometimes get an multi-threading
error like "cross thread operation is not valid" although my code is
in background workers_doWork event.

You can't directly access your forms controls in the DoWork event. That
event is running on another thread, and will cause the above error to be
generated. If you need to update your UI from the DoWork event, then
you need to call the ReportProgress method from you DoWork event and
handle the ProgressChanged event. It's safe in ProgressChanged, because
the BackgroundWorker takes care of the cross thread marshalling for you.
You can also do any finish up work in the RunWorkerCompleted event...
 
H

hngo01

Here is my code...

Dim oProcessChanges As New clsProcessChanges 'clsProcess_Changes
Dim t As New Thread(AddressOf oProcessChanges.ProcessChanges)

oProcessChanges.ReqInfo = oReqInfo
oProcessChanges.CurrentValues = oCurrentValues
oProcessChanges.gCourse_ds = CopyDataSet(gCOURSE_DS) 'gDupDataSet
oProcessChanges.pnlControls =
Me.pnlReqInfo.Controls("ucRequestInfo").Controls
oProcessChanges.RequestID =
dgPendingApps.CurrentRow.Cells(dgPendingApps.ColumnCount - 1).Value.ToString
oProcessChanges.AppORReimb = Me.Tag

t.Start()
 

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