做数据库写入响应之后 [英] doing database write after the response

查看:104
本文介绍了做数据库写入响应之后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个接收来自用户的请求,并返回一些JSON的Web服务。我需要保存JSON字符串中的数据库,因此就目前而言,发生写入查询之前发回的响应。

I have a web service that receives requests from users and returns some json. I need to save the json string in the database so for the moment, the write query occurs before the response is sent back.

有没有一种方法,首先发送响应,然后做查询写,后的反应留下的网络服务?

Is there a way to send the response first and then do the write query, after the response left the web service?

感谢。

推荐答案

您可以做类似安排。

ThreadPool.QueueUserWorkItem(state => 
      this.AsynchronousExecuteReference());

 // and run
 static void AsynchronousExecuteReference()
 {
    // run here your sql update
 }

另外一个例子使用一个线程类中,你可以传递参数给它。

One other example using Thread inside an class and you can pass parameters to it.

public class RunThreadProcess
{
    // Some parametres
    public int cProductID;

    // my thread
    private Thread t = null;

    // start it
    public Thread Start()
    {
        t = new Thread(new ThreadStart(this.work));
        t.IsBackground = true;
        t.SetApartmentState(ApartmentState.MTA);
        t.Start();

        return t;
    }

    // actually work
    private void work()
    {
        // do thread work
        all parametres are available here
    }
}

这是我如何运行它

  var OneAction = new RunThreadProcess();
    OneAction.cProductID = 100;
    OneAction.Start();

不要担心内存,CG知道,使用这种过程,直到线头,所以我必须检查和CG不要删除它,并等待线程结束。

Do not worry about memory, CG knows that this process is used until the thread ends, so I have check it and CG not delete it and wait the thread to ends.

这篇关于做数据库写入响应之后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆