【问题标题】:C# Wait Handle for CallbackC# 等待回调的句柄
【发布时间】:2013-02-28 12:33:02
【问题描述】:

我的一些方法有问题,我认为 WaitHandle 是解决方案。

我通过 API 为 Ticketsystem 创建一个事件。

private void create_Incident(string computer_idn, string swidn_choice, 
string swName_choice, string CI_Number, String windows_user)
{
    string msg_id = "" + computer_idn + "_" + swidn_choice + "";
    string username = "BISS";

    hajas211ilt3.ILTISAPI api = new hajas211ilt3.ILTISAPI();
    api.BeginInsertIncident(username, "", msg_id, "", "", "2857", 
    "BISS - Software Deployment", "", "", "NOT DETERMINED",
    "", "", "", "", "", "", "5 - BAU", "3 - BAU", "", 
    "Interface", "", "", "", "", "", "", 
    delegate(IAsyncResult r) 
    { InsertIncidentCallback(api, r, username, msg_id); }, null);

}

此方法在 create_Incident 方法中作为回调调用。

private void InsertIncidentCallback(server3.ILTISAPI api, IAsyncResult result,
 string username, string msg_id)
{
    api.EndInsertIncident(result, out message);
}

我需要 if 中的消息,但我需要安全性,即有消息。所以我必须等待 InsertIncidentCallback 和消息。

在我问的另一种方法中,消息是否正常:

private void checkIncident(string omputer_idn, string swidn_choice, 
                           string swName_choice, string CI_Number, 
string windows_user)
    {
        if (message == null)
        {
            string responseXML;
            api.REMEDY_ReadResponseXML(username, out responseXML, out msg_id);
            XDocument doc = XDocument.Parse(responseXML);
            inquiryId = (string)doc.Root.Element("inquiry_id");

            if (inquiryId == null || inquiryId == "")
            {
                information_text.Text = ".....";
            }
            else
            {
                information_remedyID.Visible = true;
                information_remedyID.Text = inquiryId;
                create_LanDesk(computer_idn, swidn_choice, 
                swName_choice, inquiryId);
            }
        }
        else
        {
            information_text.Visible = true;
            information_text.Text = "....";
        }
    }

如何为回调实现 WaitHandle?在这种情况下,WaitHandle 是正确的选择吗?

【问题讨论】:

  • 你实际上并没有说问题是什么,只是你的一些方法有问题。
  • 如何实现回调的 WaitHandle?在这种情况下,WaitHandle 是正确的选择吗?
  • 在什么情况下?你说有一个问题让你想到了等待句柄,但那个问题是什么?即I have a Problem with some of my Methods and I think, a WaitHandle is the solution.
  • 对不起。回调是一个后台进程,我想显示客户知道他的票号的inquiryId。问题:当消息不为空或“”时,我必须等待回调原因,票证有问题,票证系统从未创建响应xml。我的想法是等待回调安全,票证已完成,我可以获得 responseXML。

标签: c# asp.net methods callback waithandle


【解决方案1】:

在您的 AppPool 线程上使用 WaitHandle,从而导致它们无限期地等待将很快使您的服务器瘫痪。

别这样。

您可以在网络上使用多种替代方法来解决此问题。

当您发送此回复时,您可以向用户显示一条消息“处理中”。

当您收到响应时,会将结果存储在该异步调用中,您可以使用 SignalR 之类的框架将其推送给用户。

或者,您可以将结果存储在 Session 变量中,并使用 UpdatePanel 在间隔后刷新和显示状态。

【讨论】:

  • 服务器为什么会宕机?
  • Asp.net 在 AppPool 中的线程数量有限(25 到 100 之间,具体取决于您的服务器)。每个请求都需要一个线程。如果锁定这些线程,服务器将无法处理请求。如果您必须让页面等待,请搜索如何使用“异步页面”。这些将允许您使用IAsyncResult.AsyncWaitHandle 中的InsertIncidentCallback 而不会阻塞线程
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多