interrupt a blocking call

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

Hi,

Need some suggestions:

What is the best way to interrupt a blocking function call? I have a
synchronized method which might take a long time to complete, and the time
to complete the work is really depending on network condition and the server
workload. I want to give users a way to break it up instead of waiting for
the WaitCursor forever.

trying to have anothe thread throw an exception and hoping the othe thread
can catch it to beak it up. I found the other thread is not catching the
exception thrown by other thread. Does it make sense? Am I still able to
make it this way? Or other alternative to achieve the same objective?

Thanks in advance.
Sean
 
What is it blocking *on*? Every case will be broken in a different way, for
cleanest exit.

Paul T.
 
I probably not using the right terminology. Sorry ... I probably should
just state it as a synchronized function call (vs. async)

When the method is called, it is not returned until data is processed
completely. I need to find a way to return the "wait-too-long" error to the
appl, such that the appl can show the error to users or take other
approaches, etc.
 
Well, the way Windows does it is to return a value indicating the things are
in progress. Presumably, you'd also have a means for the UI thread to join
the actual data processing thread (you'll be using threads, if you want two
things, the UI and the process, to run at once), when it's time, as well as
some means of checking status or reporting progress. As for how you decide
that you've waited too long and should fork the remaining processing off
into a thread, that's going to be a custom thing. You'll probably do
something like this:

UI Thread
-----------

int StartPotentiallyLongProcess()
{
Create thread to do the process.

Wait for thread exit for some period of time, 1 second, say.

If Wait returned time-out, the process is going to be a while, so return
WORKING_ON_IT
If Wait returned an indication that the thread was done, return DONE
}

Paul T.
 
You still didn't answer the question so let me try phrasing it a different
way:

Given (pseudo code):

void BlockingFunc(...)
{
DoSomeProcessing();
WaitForSomethingToHappen();
DoSomeMoreProcessing();
}

What does YOUR code do in place of WaitForSomethingToHappen() this will
determine the appropriate mechanism for doing timeouts. (There are many
different possibilities each with it's own unique solution so you need to
provide that info before anyone can be of any real help).
 
The "DoSomeProcessing" invoke a webservice to a remote transaction service,
which probably get blocked in the backend for some unknown reason to me.

The "WaitForSomethingToHappen" pretty much only show users the status of the
remote transaction status, if the webservice function call returns.

I want to improve user experience is by adding some code "DoSomeMoreProcess"
such that it tell users, "Server is busy, try again or adandon?".

The suggest I got from Paul works. I am still open for more oppinions to
learn more.

Best Regards,
Sean
 
Back
Top