in Search
 
Home Forums Marketplace Files
 
 
 

COM Events not firing in Windows Service

Last post 07-02-2009, 11:37 AM by Justin.Killen. 1 replies.
Sort Posts: Previous Next
  •  07-01-2009, 11:01 PM 14752

    COM Events not firing in Windows Service

    Hi all.  I've developed a VERY basic C# command-line program that subscribes to the OnNewFaxEvent of the COM API's FaxServer object.  I have it set up as follows (pseudo-code):

    var faxServer = new FaxServer(){ //properties set up here };
    faxServer.OpenServer();
    faxServer.Events.Interval = 5;
    faxServer.OnNewFaxEvent += (delegate(Fax fax) { //write to c:\faxLog.txt file here. });
    User rfUser = faxServer.get_User("TEST");
    faxServer.Events.set_WatchNewFaxes(rfUser, BoolType.True);

    while(true)
      Thread.Sleep(5000);

    This code works beautifully in the command line app.  I can capture all of the new fax events for the "TEST" user.  The problem is that when I directly port this code to a windows service the events stop firing.  There is no error thrown, I can debug the service and I see it continuously pausing on the "Thread.Sleep" line, but NO events are received from RightFax.

    I thought it might be the logon the service was using, but I tried the Local System account, my account, and a domain administrator account.  No luck.

    I am using RightFax 8.7, by the way.  Any ideas?

  •  07-02-2009, 11:37 AM 14754 in reply to 14752

    Re: COM Events not firing in Windows Service

    From what I have seen, most COM components don't like being run from within a service.  It's got to do with a service being in a multi-threaded compartment (MTA) whereas COM components typically want to be in a single-threaded compartment (STA).

    Not sure if this is the case with rightfax, but I have seen some weird issues that have gone away if you add the code to run the com in an STA.  For an example of how to set this up, see my posting in this thread:

    http://www.captaris.com/DeveloperProgram/forums/permalink/14719/14737/ShowThread.aspx#14737

View as RSS news feed in XML
  Privacy    Site Terms   Contact Administrator