string result ="{"AppointmentID":463236,"Message":"Successfully Appointment Booked","Success":true,"MessageCode":200,"isError":false,"Exception":null,"ReturnedValue":null}"
dynamic d = JsonConvert.DeserializeObject<dynamic>(result);
Run Code Online (Sandbox Code Playgroud)
d.GetType()为Newtonsoft.Json.Linq.JObject
那么如何将其反序列化为动态对象而不是 JObject
所以我在MVC控制器方法里面有以下代码:
public ActionResult ProcessFile ()
{
ThreadStart threadStart = new ThreadStart ( ()=>{
// Doing some long processing that takes 20 minute
} );
Thread thread = new Thread(threadStart);
thread.Start();
}
Run Code Online (Sandbox Code Playgroud)
这里的问题是当多个请求发送到此控制器方法时,线程被杀死.我需要Thread继续工作,直到处理结束,似乎资源占用了大量资源,线程可以继续工作.如果我从Windows应用程序或服务运行该过程它完美地工作,它只是从Web应用程序启动时遇到问题.
根据以下单元测试方法,StringBuilder远比String.Replace慢,为什么每个人都说StringBuilder更快?我错过了什么吗?
[TestMethod]
public void StringReplace()
{
DateTime date = DateTime.Now;
string template = File.ReadAllText("file.txt");
for (int i = 0; i < 100000; i++)
{
template = template.Replace("cat", "book" );
template = template.Replace("book", "cat");
}
Assert.Fail((DateTime.Now - date).Milliseconds.ToString());
}
[TestMethod]
public void StringBuilder()
{
DateTime date = DateTime.Now;
StringBuilder template = new StringBuilder(File.ReadAllText("file.txt"));
for (int i = 0; i < 100000; i++)
{
template.Replace("cat", "book");
template.Replace("book", "cat");
}
Assert.Fail((DateTime.Now - date).Milliseconds.ToString());
}
Run Code Online (Sandbox Code Playgroud)
结果如下:
StringReplace - 335ms
StringBuilder - 799ms