데이터베이스 이벤트를 수신하고 여러 장치에 정보를 보내는 ASP.NET에서 알림 시스템을 만들려고합니다.
다음은 이벤트 포착을 담당하는 클래스의 샘플입니다.
public class FbEventClass
{
private static FbEventClass eventController = null;
public static void CreateEventController(string connectionString)
{
if (eventController == null)
{
eventController = new FbEventClass(connectionString);
eventController.AddListener(MessageListener);
}
}
FbConnection connection;
FbRemoteEvent revent;
public FbEventClass(string connectionString)
{
connection = new FbConnection(connectionString);
connection.Open();
revent = new FbRemoteEvent(connection);
revent.AddEvents(String[] { "TEST" });
}
public static void MessageListener(object sender, FbRemoteEventEventArgs e)
{
SendNotification("Message recieved");
}
}
컨트롤러에서 정적 개체를 만듭니다.
FbEventClass.CreateEventController(dt.connectionString);
문제는 MessageListener () 메서드가 호출되지 않는다는 것입니다. 컨트롤러를 다시 호출하면 개체가 null이 아닙니다.
마침내 답을 찾을 수있었습니다. 완벽한 솔루션은 아니지만 저에게는 효과적입니다. 방금 CreateEventController ()를 스레드에 추가했습니다.
ThreadPool.QueueUserWorkItem((o) =>
{
FbEventClass.CreateEventController(cc);
});
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다