Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way and recommended practices for interacting with Lotus Notes from C#

In particular, I have to extract all the messages and attachments from Lotus Notes files in the fastest and most reliable way. Another point that may be relevant is that I need to do this from a secondary thread.

Edit

Thanks for the answers - both of which are good. I should provide more background information.

We currently have a WinForms application with a background thread using the Notes COM API.

However it seems to be unstable. (Of course it may be we are doing something wrong.) For example, we have found we have to preinitialize the Notes session on the main thread or else the call to session.CreateDXLExporter() on the background thread throws an exception.

like image 577
Phil Haselden Avatar asked Sep 05 '08 02:09

Phil Haselden


People also ask

Why is Lotus Notes better than Outlook?

The maintenance of Outlook is much simpler and easier as compared to Lotus notes and the cost of maintenance is not that high as IBM Notes. The Lotus Notes is compatible with almost every operating system including Linux, Windows, and Mac.

Is IBM Notes still supported?

For IBM Notes/Domino 9.0, we have announced that product support will be extended through at least 2021, and extended support through at least 2024.

What database does Lotus Notes use?

The Notes Storage Facility (NSF) non-relational database file is used by IBM Lotus Notes and Domino software to store different kinds of data stored in Notes including email messages, chat and instant messages, documents, appointments and other calendar entries.


1 Answers

I really do hate that NotesSession COM object.

You cannot use it in another thread than the thread it was initialized. Threads in .NET are fibers, the real underlying thread may change at any time.

So I suggest using it this way, in a using block :

Imports Domino
Imports System.Threading

Public Class AffinitedSession
    Implements IDisposable

    Private _session As NotesSession
    Public Sub New(ByVal pass As String)
        Thread.BeginThreadAffinity()
        _session = New NotesSession()
        _session.Initialize(pass)
    End Sub

    Public ReadOnly Property NotesSession() As NotesSession
        Get
            Return _session
        End Get
    End Property

    Private disposedValue As Boolean = False        ' To detect redundant calls

    ' IDisposable
    Protected Overridable Sub Dispose(ByVal disposing As Boolean)
        If Not Me.disposedValue Then
            If disposing Then
                ' TODO: free other state (managed objects).
            End If

            ' TODO: free your own state (unmanaged objects).
            ' TODO: set large fields to null.
            _session = Nothing
            Thread.EndThreadAffinity()
        End If
        Me.disposedValue = True
    End Sub

#Region " IDisposable Support "
    ' This code added by Visual Basic to correctly implement the disposable pattern.
    Public Sub Dispose() Implements IDisposable.Dispose
        ' Do not change this code.  Put cleanup code in Dispose(ByVal disposing As Boolean) above.
        Dispose(True)
        GC.SuppressFinalize(Me)
    End Sub
#End Region

End Class

Notice the Thread.BeginThreadAffinity() and the Thread.EndThreadAffinity()

Those are your friends.

Cheers !

like image 140
Alex Rouillard Avatar answered Oct 11 '22 18:10

Alex Rouillard