Home All Groups Group Topic Archive Search About
Author
27 Nov 2007 4:26 PM
PGP
Hello,

I have a library which does some database operations. There are threads in
the library which are transparent to the user. Database operations are done
in threads as they could be lengthy. When an exception occurs in a library
thread, i want to make this exception available to the user (user is usually
in the app's main thread). What is the common practice in such a scenario?

TIA
Priyesh

Author
28 Nov 2007 5:42 PM
jehugaleahsa@gmail.com
On Nov 27, 9:26 am, "PGP" <priyesh_do_not_reply> wrote:
> Hello,
>
> I have a library which does some database operations. There are threads in
> the library which are transparent to the user. Database operations are done
> in threads as they could be lengthy. When an exception occurs in a library
> thread, i want to make this exception available to the user (user is usually
> in the app's main thread). What is the common practice in such a scenario?
>
> TIA
> Priyesh

Remember that threads share memory. They simply have their own
instruction pointer and stack. If you have one thread raise a
MessageBox, it will show up. If you modify a GUI, it will modify the
UI, not a copy of the UI. You simply have to ensure you have
concurrency. The common problem is that the thread starts at a point
such that it doesn't have any access to the interface. Well, you can
have the thread start in a method that is still at the interface
level, then wrap the non-interface code in a try/catch.

void threaded() // this is the entry-point of your thread
{
   try
   {
       // start DB code
   }
   catch
   {
       // do UI concurrency to handle error.
   }
}

You do most UI concurrency using BeginInvoke and EndInvoke. You should
be able to get what you want from what I have said.
Author
29 Nov 2007 12:28 AM
PGP
<jehugalea***@gmail.com> wrote in message
Show quote
news:b6753f0a-bac9-433a-b531-5930802cad5d@i12g2000prf.googlegroups.com...
>
> Remember that threads share memory. They simply have their own
> instruction pointer and stack. If you have one thread raise a
> MessageBox, it will show up. If you modify a GUI, it will modify the
> UI, not a copy of the UI. You simply have to ensure you have
> concurrency. The common problem is that the thread starts at a point
> such that it doesn't have any access to the interface. Well, you can
> have the thread start in a method that is still at the interface
> level, then wrap the non-interface code in a try/catch.
>
> void threaded() // this is the entry-point of your thread
> {
>   try
>   {
>       // start DB code
>   }
>   catch
>   {
>       // do UI concurrency to handle error.
>   }
> }
>
> You do most UI concurrency using BeginInvoke and EndInvoke. You should
> be able to get what you want from what I have said.

I do have a need to pass the Exception object back to the user. This i do
right now
by raising an event from catch handler with the exception in the event args.
This seems to work
correctly. One of my initial doubts was that if it would have lifetime
issues with the
exception object as it was created in another thread. Any information on why
this works
correctly will be helpful.

AddThis Social Bookmark Button