On Nov 27, 9:26 am, "PGP" <priyesh_do_not_replywrote:
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.