0

我的一些方法有问题,我认为 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 是正确的选择吗?

4

1 回答 1

1

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

不要这样做。

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

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

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

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

于 2013-02-28T12:41:30.680 回答