C#等待回调处理 [英] C# Wait Handle for Callback

查看:575
本文介绍了C#等待回调处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a Problem with some of my Methods and I think, a WaitHandle is the solution.

我通过故障单的API创建事件.

I create a Incident through a API to a 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方法中称为回调.

This method called as a callback in the create_Incident method.

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

如果需要,我需要消息,但为了安全起见,我需要一条消息.因此,我必须等待InsertIncidentCallback和消息.

I need the message in a if, but I need the safety, that there is a message. So I have to wait for the InsertIncidentCallback and the message.

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

In a other Method I ask, if the message is ok:

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是正确的选项吗?

How can I implement a WaitHandle to the Callback? Is the WaitHandle the right option in this case?

推荐答案

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

Using a WaitHandle on you AppPool threads, thus causing them to wait indefinitely would quickly bring your server to its knees.

不要这样做.

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

There are several alternatives that you can use on the web to work around this.

发送此回复时,您可以向用户显示一条消息,提示正在处理".

You could display a message to the user saying "Processing" when you send this reply.

当您收到响应存储的结果时,可以使用 SignalR .

When you receive the response store the result on that async call you can push it to the user using a framework like SignalR.

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

Alternatively you could store the result in a Session variable and use an UpdatePanel to refresh and show the status after an interval.

这篇关于C#等待回调处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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