Transactional Program Question

P

Paul

I have a VB.NET 2005 program that I am running. It is transactional
in nature and most of the steps are running a query against SQL Server
tables. I have one executable that displays one form. The form
displays what step is currently running, start time, end time, etc. I
want to be able to minimize the form or move it around while the steps
are running. However, I cannot due to the steps are waiting to return
from SQL Server.

Is this something that I need to use threading with? Or is there a
better answer?
 
T

Tom Shelton

I have a VB.NET 2005 program that I am running. It is transactional
in nature and most of the steps are running a query against SQL Server
tables. I have one executable that displays one form. The form
displays what step is currently running, start time, end time, etc. I
want to be able to minimize the form or move it around while the steps
are running. However, I cannot due to the steps are waiting to return
from SQL Server.

Is this something that I need to use threading with? Or is there a
better answer?

In VB.NET 2005, I would look at the BackgroundWorker component...
This will allow you to run the queries in the background, do status
updates, cancelation, etc - without having to worry so much about
cross thread marshalling.
 
C

Cor Ligthert [MVP]

Paul,

If you would do multithreading with your process, than you would in my idea
do the printing in Background. However that is already standard done,
probably and by your printer buffer and secondly even by your
printerspooling.

What is the reason that those not are working?
(As you have disabled those that multithreading is probably as well without
sense)

Cor
 
P

Paul

Thanks for the responses. I've started to look at the
BackgroundWorker component and will see if that works. Anyone have a
good link as to how it works? The help in MSDN is not that helpful.

Cor, I'm doing very little printing. Most of the steps are INSERT,
DELETE or UPDATE statements against SQL Server 2005 tables. The
program I am writing is a night job program that will run 31 steps.
One of the steps is to print a report. I just want my UI to respond
to user input (i.e.: minimize, view status, etc.) while the 31 steps
continue to run.
 
P

Paul

One more thing. Each step needs to complete before the next step is
to run. That is why I'm having trouble with threading. I can start a
thread but I don't know how to wait for it. Using the .Join does not
work because it also causes the UI to not be responsive.
 
P

Paul

I created an example using a BackgroundWorker. It doesn't help me.
It works just like a threaded process (which it's supposed to). I run
the BW using RunWorkerAsync and the process starts running. But then
it runs the line after the RunWorkerAsync command. I need it to wait
until it returns.

How do I do this and still have the UI responsive?
 
C

Cor Ligthert [MVP]

Paul,

This problem is in my idea only to solve with quicker hardware.

Cor
 
P

Paul

Well, I got it to work...

I'm not sure this is the "best" way of doing it. But it works. My
base form starts the BackgrounWorker object. Then the
"RunWorkerCompleted" event is fired when the BW is done. The code for
that sub is below:

Private Sub myBackgroundWorker_RunWorkerCompleted(ByVal sender As
Object, _
ByVal e As
System.ComponentModel.RunWorkerCompletedEventArgs) _
Handles myBackgroundWorker.RunWorkerCompleted
RaiseEvent BackgroundWorkerCompleted(e)
End Sub

This is event is captured by my form which starts the BW again with
the next step. I thought about starting the BW from within the
"RunWorkerCompleted" event, but I wasn't sure it would work and I
didn't want threads starting all over the place.

I appeciate hearing from anyone who has done this before in a better
way. However, I think my solution will work.
 

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