在后端仍在处理时是否可以中断进程?

时间:2017-07-05 09:08:17

标签: javascript c# asp.net ajax webforms

我想问一下,我是否可以通过向后端发送另一个请求来中断进程?

例如:我向服务器发送请求,后端正在处理请求。虽然后端仍在忙于处理请求,但我将通过向服务器发送另一个请求来告知进程停止来中断该过程。这有可能实现吗?

以下是我的示例代码:

`//Ajax code for sending request for starting the process for looping
function showSomething(){
 $(function (){
   $.ajax({
      type: 'POST',
      data: JSON.stringify({something : ''}),
      url: 'veryGoodForSomething.aspx/checkSomething',
      contentType: 'application/json;charset=utf-8',
      dataType: 'json',
      success: function (response){
      //do something
      windows.location.hostname;
      location.reload(true);
      }
   });
 });
}`
  

ajax会将启动进程的请求发送到后端。

`//this code will execute for checking
public static bool checkSomething(string something)
{
  bool checking = false;
  while(!checking)
  {
     if(string.isNullOrEmpty(something)){
        checking = furtherChecking(something);
     }
     else
     {
        return checking;
     }
  }
  return checking;
}`

现在虽然后端仍在处理检查某些内容,但我想通过使用ajax发送另一个请求来中断该过程。

`//This will interrupt the process by sending 'interrupt' to trigger the
//backend to stop the process while the backend is still running the looping 
//process.
function interruptSomething(){
  $(function () {
    $.ajax({
      type: 'POST',
      data: JSON.stringify({ something : 'interrupt'}),
      url: 'veryGoodForSomething.aspx/checkSomething',
      contentType: 'application/json;charset=utf-8',
      dataType: 'json',
      success: function(response){
         location.reload(true);
      }
    });
  });
}`
  

发送请求'中断'而后端仍然在运行。这个过程会破裂。

真正的问题是,这是可以实现的吗?有人可以帮我解决这个问题,或者有人能为我提供一个很好的参考资料吗?

0 个答案:

没有答案