Notifying the user of the current action

  • Thread starter Thread starter Stropher
  • Start date Start date
S

Stropher

Hi!

I have a db-query which takes too long to complete. In this process, it
will not be bad notifying the user that something is being done so as
to exercise some patience. How can I realise this? With the help of
thread, but how?

Thanks in advance...
Stropher
 
Hi,
btw msdn samples and even if you write "thread class" on index can guide you
to the use of threads. Its really very simple (although synchroniztion can
be from simple to very hard based on the kind of work u r doing). But the
notification may not be there in the code. So I'm writing a little code for
you here that may help you out trying to do your work:

we start a thread like this:

Thread thread = new Thread ( new ThreadStart ( this.threadproc));
thread.Start ();

The thread proc is defined as:
void threadproc()
{
// add thread execution logic here, maybe your query execution code or
whatever.

/* NOTIFICATION PART: This is important. Assuming that you r writing this
code inside a windows form class.
Than "this" would refer to windows form itself. I'm going to make an
"asynchronous" call to a method of the form class so that it knows that the
thread is finished execution and the rest of the logic based on the thread's
results can be started.
*/

this.BeginInvoke(new dlgcallwhendone (this.callwhendone) );
}

here I'v declared the delegate "dlgcallwhendone" with callwhendone()
signatures which is our custom method here.

delegate void dlgcallwhendone();

void callwhendone()
{
MessageBox.Show ( "Thread is done executing.");


}

Well I hope this helps.

Ab.
http:://joehacker.blogspot.com
 
Back
Top