|
 |
|
[C#.NET] ใช้ jQuery $.post() + setInterval เพื่อ feed ข้อมูล แล้ว IIS หยุดทำงาน |
|
 |
|
|
 |
 |
|
ผมได้สร้างไฟล์ asp เพื่อทำการ update ข้อมูลทุก 1 วินาที เมื่อ deploy แล้วใช้งาน พอเว็บทำงานไปซักพักแล้ว IIS จะหยุดทำงานครับต้อง restart IIS ใหม่ถึงจะใช้งานได้
ทดสอบกับ เครื่องที่ทำงาน กับที่บ้านแล้วเป็นเหมือนกันเลยครับ หาสาเหตุไม่เจอ ใครพอทราบสาเหตุช่วยหาทางออกให้ทีครับ
ขอบคุณครับ
** ลองใช้ jQuery Ajax , ลองเปลี่ยนเป็น setTimeOut แล้วเป็นเหมือนกันครับ
หน้าที่รับข้อมูลมาแสดง
Code (ASP)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="recv.aspx.cs" Inherits="test.dev.recv" %>
<!DOCTYPE html>
<META HTTP-EQUIV="REFRESH" CONTENT="300">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="../Scripts/jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(function () {
setInterval(function () {
$.post("send.aspx", function (data) {
$("#recv").text(data);
});
}, 1000);
});
</script>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div id="recv" align="center">
</div>
</form>
</body>
</html>
หน้าที่ query แล้วส่งข้อมูลกลับ
Code (C#)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace test.dev
{
public partial class send : System.Web.UI.Page
{
dbConfig clsdb = new dbConfig();
SqlConnection conn;
SqlDataReader dtReader;
string sql;
SqlCommand cmd;
protected void Page_Load(object sender, EventArgs e)
{
call();
}
void call()
{
conn = clsdb.Conn();
sql = "select * from mytable";
cmd = new SqlCommand(sql, conn); dtReader = cmd.ExecuteReader();
sendres.InnerHtml = "";
while (dtReader.Read())
{
sendres.InnerHtml += dtReader["name"].ToString() + " : ";
sendres.InnerHtml += dtReader["email"].ToString() + "<br>";
}
Response.Write(DateTime.Now.ToString("hh:mm:ss"));
}
}
}
Tag : .NET, JavaScript, jQuery, Web (ASP.NET), C#, IIS

|
ประวัติการแก้ไข 2018-05-17 19:40:36 2018-05-17 19:46:51 2018-05-17 19:53:05
|
 |
 |
 |
 |
Date :
2018-05-17 19:38:26 |
By :
popypreaw |
View :
1071 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ใช้การส่งแบบนี้เกิด Request ค้างครับ IIS ทำงานไม่ไหวครับ ลองดูพวกเทคโนโลยี่ที่ทำงานแบบ Realtime ครับ
SignalR ครับ
|
 |
 |
 |
 |
Date :
2018-05-19 14:28:54 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|