vb.net Threading Question

  • Thread starter Thread starter mmitchell
  • Start date Start date
M

mmitchell

I have a thread that does periodic database maintenance. While this
process is going on I would like the rest of the application to hold
off on accessing the database. I thought I could share a property in a
class to hold the status, but that doesn't seem to work.

Any ideas on what the best way for me to determine when the thread is
doing it's work?

Thanks
Mike
 
Mike,
I have a thread that does periodic database maintenance. While this
process is going on I would like the rest of the application to hold
off on accessing the database. I thought I could share a property in a
class to hold the status, but that doesn't seem to work.

Any ideas on what the best way for me to determine when the thread is
doing it's work?
Don't use a thread, wait until the process is done.

(You can show a nice wait cursor on your screen)

Cor
 
I have a thread that does periodic database maintenance. While this
process is going on I would like the rest of the application to hold
off on accessing the database. I thought I could share a property in
a class to hold the status, but that doesn't seem to work.

Any ideas on what the best way for me to determine when the thread
is doing it's work?

The simplest thing is probably using Synclock on the Connection object.


Armin
 
Mike
Thanks, but in this case the thread is required.

What are than the things the users should be able to keep on doing while he
cannot get information?

To give us an impression.

Cor
 
Here is one scenerio.

A thread continually checks the Sql Server to make sure it is available
and is responsive.
This is done so that another part of the app can gather information and
post it to the Sql Server without waiting for connection time out's
etc. The information gathering has to work without interuption. If the
Server is not responsive, then the information gathering saves the
information to a local workstation and will try later to post.

So, if the thread is checking the pulse of the Sql Server, how do I let
the main part of the app know that the pulse is good?
 
I think I have found my answer in on-line help..

Returning values from procedures that run on separate threads is
complicated by the fact that the procedures cannot be functions and
cannot use ByRef arguments. The best way to return values is to have
your multithreaded procedure call a procedure in your application, and
then pass the results as arguments. To do this, raise an event when a
task is done, and process the results with an event handler.

The following example returns a value by raising an event from a
procedure running on a separate thread:
 
Mike,

Probably would I set the checks in a Thread with just a global switch that
tells that the server is available or not. In principle does only that
thread change this switch. (However, see the rest)

The only part that the mainthread does than looking at this switch to decide
to save or to update it.

When you start your maintenance you can use another switch that prevents
this process to change the first switch and set this first switch (therefore
it has on both places to be synclocked).

While the maintenance switch is busy the first switch is not updated by the
checking thread (it even can be aborted).

Probably I would use two switches to stop the checking thread as well.

If I wrote something wrong it is more the idea.

Just my thought,

Cor
 
I think I have found my answer in on-line help..

Returning values from procedures that run on separate threads is
complicated by the fact that the procedures cannot be functions and
cannot use ByRef arguments. The best way to return values is to have
your multithreaded procedure call a procedure in your application,
and then pass the results as arguments. To do this, raise an event
when a task is done, and process the results with an event handler.

The following example returns a value by raising an event from a
procedure running on a separate thread:


I thought it was a synchronization problem, not a
how-to-return-results-from-a-thread problem.

Armin
 

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

Back
Top