Home All Groups Group Topic Archive Search About

vb.net Threading Question

Author
27 Jun 2005 5:13 PM
mmitchell@capstonetechnology.com
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

Author
27 Jun 2005 6:18 PM
Cor Ligthert
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
Author
27 Jun 2005 6:28 PM
mmitchell@capstonetechnology.com
Thanks, but in this case the thread is required.
Author
27 Jun 2005 6:57 PM
Cor Ligthert
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
Author
27 Jun 2005 7:18 PM
mmitchell@capstonetechnology.com
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?
Author
27 Jun 2005 7:38 PM
Cor Ligthert
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
Author
27 Jun 2005 6:39 PM
Armin Zingler
<mmitch***@capstonetechnology.com> schrieb
> 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
Author
27 Jun 2005 7:26 PM
mmitchell@capstonetechnology.com
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:
Author
27 Jun 2005 7:49 PM
Armin Zingler
<mmitch***@capstonetechnology.com> schrieb
> 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