Dim dlgtDoSearch As New DoSearchDelegate(AddressOf wrp.doSearch)
Dim stateAsync As New AsyncSearchResultsState(Session.SessionID, sDsName)
AsyncClearSessionElement(sDsName)
Dim acb As New AsyncCallback(AddressOf SearchResultsAsyncCallBack)
dlgtDoSearch.BeginInvoke(queryState, maxResultsPerPage, PageNumber, acb, stateAsync)
Public Sub SearchResultsAsyncCallBack(ByVal ar As IAsyncResult)
Dim ard As AsyncResult = CType(ar, AsyncResult)
Dim dlgtDoSearch As DoSearchDelegate = CType(ard.AsyncDelegate, DoSearchDelegate)
Dim result As Object 'possible types - DataSet or Exception
Try
result = dlgtDoSearch.EndInvoke(ar)
Catch exc As Exception
result = exc
End Try
StoreInSessionManager(ar, result)
End Sub 'SearchResultsAsyncCallBack
'//Dim result As Object 'possible types - DataSet or Exception
Public Sub StoreInSessionManager(ByVal ar As IAsyncResult, ByVal result As Object)
'store the values in the data store
Dim myState As AsyncSearchResultsState = CType(ar.AsyncState, AsyncSearchResultsState)
Dim mgr As New SessionLib.SessionManager 'required reference and CodeProject\SessionTools\Session\obj\Debug\SessionManager.dll
DebugHelper.TracedLine((" Session " + myState.SessionID + " Element is " + myState.m_sElementKey + " ResultType=" + result.GetType.ToString()))
mgr.SetSessionData(myState.SessionID, myState.m_sElementKey, result)
End Sub 'StoreInSessionManager
Sub PollSearchResults(...)
m_bRefreshRequired = False
Dim mgr As New SessionLib.SessionManager 'alternatively use Asynchronous Invocation Application Block
Dim res1 As Object = mgr.GetSessionData(Session.SessionID, sDsName)
DebugHelper.TracedLine(" Session " + Session.SessionID + " Element is " + sDsName)
If (Not IsNothing(res1)) Then '
'long task is complete, goto the results
If TypeOf res1 Is SearchResultsDatasetBase Then
'Only the first time when the search results are polled, poll is required
'The simplest way is to check if sessnDataset.Dataset is null or not,
'TODO: may be check at the beginning and exit sub immediately
'Alternatively I can save some flag to SearchResultsDatasetBase (or save special type to sessionManager)
'that will indicate that reading is done
If IsNothing(sessnDataset.Dataset) Then
DataBind(res1,...)
End If
ElseIf TypeOf res1 Is Exception Then
BaseResultItemsListUsc.LogWarningAndShowError(listResults, res1)
Else
Throw New ExceptionWithDetails("Unexpected Asynchronous results type returned", res1.GetType.ToString)
End If
Catch ex As Exception
BaseResultItemsListUsc.LogWarningAndShowError(listResults, AppEventLogName, ex, resType, queryState)
Finally
If Not listResults Is Nothing Then
listResults.LabelCaption.Visible = True
End If
End Try
Else
m_bRefreshRequired = True
End If
If m_bRefreshRequired = True Then
JScriptHelper.SetRefresh(Page, 5)
End If
End Sub