0

I have developed a vb.NET dll that raises events which I want to handle from an asp application. So far, I managed to handle the events from the asp application, store event's data in session and then with an asp timer and an updatePanel control, I perform updates to the desired asp controls by reading session's data in each timer interval. But, if I try to update the asp controls directly from inside the code that handles an event, without using a timer and session, controls do not update. As suggested from a previous post, this happens because the code executes on the server. In a few words:

  1. Dll raises event

  2. Asp/vb code handles the event and store its data in session

  3. Timer executes every second, reads session's data and updates controls

So my question is this.

  • Is there a better approach to update the asp controls, rather than using a timer that reads every second session variables?
  • I was wondering if this issue relies on my DLL, not raising events asynchronously? Or it's just how asp/web works and there is no other workaround?

Note: I have done a lot of research on what is the best way to raise an event asynchronously in a vb.NET dll. So far I came across to the Event-based Asynchronous Pattern Overview, to Raising events asynchronously and Do events work if raised asynchronously?. From all this the Raising events asynchronously looks to me the easiest approach but it's outdated and I am having problems to implement and test it in framework 4.0. But before starting to mess around with all this I wanted a second opinion.

dll code (MyDllEvents.cls)

Public Event MyEvent(ByVal message As String)

Private Sub RaiseMyEvent(ByVal message As String)
    RaiseEvent MyEvent(message)
End Sub

Asp & vb code inside Asp application

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <ContentTemplate>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    </ContentTemplate>
</asp:UpdatePanel>

Private withevents o As new MyDllEvents.cls

Protected Sub o_MyEvent(message As String) Handles o.MyEvent
    Label1.Text = message 'not updating
    UpdatePanel1.Update() 'contains the Label1 control 
End Sub
Community
  • 1
  • 1
Spyros
  • 13
  • 4
  • If you think of the ASP.NET thread as not existing unless it is processing a request from the client, you will see that you would be better off polling the server from the client instead of trying to push data from the server. – Andrew Morton Apr 05 '14 at 22:11
  • Something like a javascript timer? Meaning that I will handle the event, store data in session and then the javascript timer will read session variables? – Spyros Apr 05 '14 at 22:45
  • You don't even need to handle the event. The code to receive the event probably won't be instantiated when the event is raised. If you need some sort of persistent storage for the data, you could use a Windows service to populate/update a database, then use a [WCF service](http://www.codeproject.com/Articles/139787/What-s-the-Difference-between-WCF-and-Web-Services) to send the data to the client when the client requests it (using a timer in Javascript). You'll have to research how to get session state in the service. – Andrew Morton Apr 05 '14 at 23:00
  • Thank you Andrew. I will researh about it. – Spyros Apr 05 '14 at 23:10

0 Answers0