views:

354

answers:

2

Hello,

I have a client-server architecture where client communicates with the server using .NET Remoting. Server handles all business logic and database interaction. I need to add an operation which may take a while to execute and the dataset it returns might be quite large. I'm thinking of employing asynchronous call for that. Now the problem arises: assume, the client made this async call, operation started SQL query, and user either closes the client or clicks Cancel -- what will happen to the operation? Is there any way to cancel the pending async call, which is busy talking to SQL server?

Thanks.

+1  A: 

You could design your client/server interaction so that the server let a worker thread do the SQL stuff so that it was ready to receive another call from the client. So, the client makes call 1 and says do SQL work. The server gives that work to the worker thread and is ready for new incoming. Then the client makes call 2 and says, "never mind". The server would do some bookkeeping to make sure it doesn't call back to the client when the worker thread is done.

Can the server safely interrupt the worker thread. I'm not sure. Would that have any affect on what SQL Server is doing. Not sure.

Corey Trager
A: 

What do you do now with call in progress when client closes application? You can do the same thing with asynchronous call.

Yes, async is the way to go for long-running requests. If result set is big enough, you can even think about sending chunks of it with several responses from server.

Of when user clicks Cancel, you would send a new message to the server stating you are not interested in results anymore. If the SQL request is running on thread pool, you cannot really cancel it.

Alexander Abramov