Support Center

FaxPrint - Threading - Single Threaded Apartment

Mike Apr 05, 2013 03:21PM EDT

Hi!

We're developing a faxing system for a client of ours using FaxMan and FaxPrint as the underlying controls. We're running in to a bit of a problem with the FaxPrint control on the client side.

Ideally we'd like to handle the FaxPrint control entirely within the main code module, so it can be accessed any time the fax client program is running. When the 'Print Complete' event fires, it should launch a 'New Fax' form which collects the receiver's fax number and other meta-data needed to send a fax.

The program initializes correctly, and catches the fax event. We're able to retrieve the fax job and the associated filename. As soon as we try to call a form, though, the application crashed with the message "ActiveX Control cannot be instantiated because the current thread is not in a single-threaded apartment".

We don't seem to have this issue if we instantiate and launch the FaxPrint object from a form. Ideally, though, we'd like this in the module so we can catch prints started at any point the program is running.


How would you handle this?

Thanks,
Mike

4 Data Techniques Responses and 3 Community Responses

Up -1 Rated Down
DTI Support  Data Techniques Employee Apr 08, 2013 09:40AM EDT

Hi Mike,

Are you using VB 6 ?

If so there's not really a way around this due to the threading model/limitations of the controls and VB.

Thanks for your interest in our products and please let us know if you have any questions.

Sincerely,
Sean
Data Techniques Support

Up -1 Rated Down
Mike  Data Techniques Employee Apr 08, 2013 04:55PM EDT

Hi Sean -

We're using VB.net, not VB6.

Thanks -
Mike

Up -4 Rated Down
DTI Support  Data Techniques Employee Apr 08, 2013 04:59PM EDT

Hi,

Sorry for the confusion, are you using the FaxMan ActiveX printer control or the .Net component ? Your exception mentioned ActiveX which is confusing.

Thanks,
Sean

Up 2 Rated Down
Mike  Data Techniques Employee Apr 08, 2013 07:07PM EDT

We're using the .Net component. The error message does indeed kick back an ActiveX error. Here's the basic structure of the code that's causing problems. The error is raised on the line 'Dim frm As New frmNewFax', in the 'handleFaxPrinted' sub.



'Public Sub InitFaxPrint()
' Try
' prntr = New FaxPrint
' prntr.PrinterName = "MCSI Fax Printer
' If Not prntr.IsPrinterInstalled Then
' prntr.InstallPrinter(Application.ExecutablePath)
' End If
' Catch ex As Exception
' handleError(ex)
' End Try
'End Sub

'Private Sub handleFaxPrinted() Handles prntr.PrintComplete
' Try
' If prntr.PrintJobs.Count > 0 Then
' Dim job As PrintJob = prntr.PrintJobs.GetNextPrintJob
' faxPrintFlNameHold = job.FileName
' Dim flid As Integer = Save_File(Nothing, "FMF", job.FileName, job.FileName, -1, "Printed From FaxPrint")
' If flid > -1 Then
' Dim commsID As Integer = insertFaxRoute(flid, "Fax Out", "Hold", fllst:=faxPrintFlNameHold & "|")
' Dim frm As New frmNewFax
' frm.del_fax_print(job.FileName)
' frm.commsID = commsID
' frm.ShowDialog()
' End If
' End If
' Catch ex As Exception
' handleError(ex)
' End Try
'End Sub

Up -4 Rated Down
DTI Support  Data Techniques Employee Apr 09, 2013 09:34AM EDT

HI,

OK, so it sounds like the control is working OK right ie you are getting the PrintComplete and the file info ? Its only when you call the form that you get the exception ?

John

Up 0 Rated Down
Mike  Data Techniques Employee Apr 10, 2013 06:02PM EDT

Correct. When the form is initialized, it crashes.

Up 0 Rated Down
DTI Support  Data Techniques Employee Apr 11, 2013 09:11AM EDT

Hi,

It sounds like one of the controls on the form has the issue with the threading. I'm not sure this is directly related to the FaxMan printer control.

Thanks for your interest in our products and please let us know if you have any questions.

Sincerely,
Sean
Data Techniques Support

This question is closed to new answers.

Contact Us