2013-02-28 76 views
0

我有一些我的方法的问题,我认为,一个WaitHandle是解决方案。C#等待句柄回调

我通过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在这种情况下是正确的选择吗?

+0

你没有真正说出问题所在,只是说你的某些方法有问题。 – webnoob 2013-02-28 12:44:29

+0

我怎样才能实现一个WaitHandle的回调? WaitHandle在这种情况下是正确的选择吗? – mnlfischer 2013-02-28 12:46:48

+0

在什么情况下?你说有一个问题让你想到等待处理,但是那个问题是什么?即''我的一些方法有问题,我认为,WaitHandle是解决方案。' – webnoob 2013-02-28 12:47:29

回答

1

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

不要这样做。

有几种方法可以在网上使用来解决这个问题。

当您发送此回复时,您可能会向用户显示一条消息,指出“正在处理”。

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

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

+0

服务器为何应该停机? – mnlfischer 2013-02-28 12:48:12

+0

Asp.net在AppPool中的线程数量有限(25到100之间取决于您的服务器)。每个请求都需要一个线程。如果您锁定这些线程,则服务器无法处理请求。如果您必须让页面等待,请搜索如何使用“异步页面”。这些将允许你使用'InsertIncidentCallback'中的'IAsyncResult.AsyncWaitHandle'并且不阻塞线程 – nunespascal 2013-02-28 13:14:00